Javascript split with RegEx

Posted by Rohan on Stack Overflow See other posts from Stack Overflow or by Rohan
Published on 2010-06-15T17:42:53Z Indexed on 2010/06/15 18:52 UTC
Read the original article Hit count: 164

Filed under:

Hey again,

I just asked a question about Regex, and received a great answer: http://stackoverflow.com/questions/3047201/javascript-split-without-losing-character

Now, I have another question.

My current Regex looks like this:

var split = text.split(/(?=\w*\d*\d:\d\d)/);

Basically, I'm trying to split using the timestamps (eg - 9:30 or 10:30, the difference between them is the extra digit in the latter). How do I go about this?

Currently, if I have these two:

9:30 pm
The user did action A.

10:30 pm
Welcome, user John Doe.

The splits are :

9:30 pm
The user did action A.
----
1
----
0:30 pm
Welcome, user John Doe.

How do I add an optional check for the first character in the timestamp?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript