-1

Below is the complete string

string = 05-28-2019 23:12:23 - Sora (Additional comments) Is this work really in progress? Please provide a realistic ETA. 05-22-2019 23:56:05 - Sam (Additional comments) Any idea on ETA?

I want to split into two different strings based on date and time

string 1 = 05-28-2019 23:12:23Sora (Additional comments) Is this work really in progress? Please provide a realistic ETA. string 2 = 05-22-2019 23:56:05 - Sam (Additional comments) Any idea on ETA?

I have used below code

<script>
var res = str.split(/^(\s\s\d+)\-(\d+)\-(\d+) (\d+)\:(\d+)\:(\d+\s\s)$/);
</script>
Raghu
  • 1
  • 1
  • `\s\s\d+` - are there really 2 spaces before the first digit of the date? – Bravo Oct 03 '19 at 23:09
  • var string = "05-28-2019 23:12:23 - Sora (Additional comments) Is this work really in progress? Please provide a realistic ETA. 05-22-2019 23:56:05 - Sam (Additional comments) Any idea on ETA?"; – Raghu Oct 03 '19 at 23:10
  • Now string 1 should be – Raghu Oct 03 '19 at 23:11
  • str1= "05-28-2019 23:12:23 - Sora (Additional comments) Is this work really in progress? Please provide a realistic ETA."; – Raghu Oct 03 '19 at 23:11
  • str2= "05-22-2019 23:56:05 - Sam (Additional comments) Any idea on ETA?"; – Raghu Oct 03 '19 at 23:12
  • why are you repeating the question in comments? I asked if the date is preceded by two spaces – Bravo Oct 03 '19 at 23:18
  • No spaces in front – Raghu Oct 03 '19 at 23:24
  • Possible duplicate of [Split Strings into words with multiple word boundary delimiters](https://stackoverflow.com/questions/1059559/split-strings-into-words-with-multiple-word-boundary-delimiters) – Henry Henrinson Oct 03 '19 at 23:37

1 Answers1

0

If you don't have any specific separator, you do have to use lookaheads in this case.

The code below would be exactly tailored to what you want to achieve.

text.split(/(?=\d{2}-\d{2}-\d{4} \d{2}\:\d{2}\:\d{2} -)/)
Lukasz032
  • 354
  • 4
  • 14