I'm looking to use reg-ex to split the following string
1 hi my name is John. 2 I live at house 32. 3 I see stars.
to
[hi my name is John,  I live at house 32. , I see stars]
Note that am trying to split on digit followed by a space
Split on /(^|\b\s+)\d+\s+/g.
Explanation:
(^|\b\s+) A collection of either ^ or \b\s+)
^ Start of the string OR\b\s+ a word boundary  followed by a space/tab repeated 1 or more times
\d+ A digit between 0 and 9 repeated 1 or more times (so it'd match 1, 12, 123, etc.)\s+ A space/tab repeated 1 or more times
Edit:
(^|\.\s+)\d+\s+ might work better for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With