I would like to split a text into groups on a special character match.
For example, the following text should be divided into three parts, splitting on each m= match:
v=0 o=NNMAS 8571 287 IN IP4
t=1358416438 0
m=audio 43538 RTP/AVP 0 8 18 96 97
c=IN IP4
a=sendrecv
m=audio 43538 RTP/AVP 0 8 18 96 97
c=IN IP4
should become
1:
v=0 o=NNMAS 8571 287 IN IP4
t=1358416438 0
2:
m=audio 43538 RTP/AVP 0 8 18 96 97
c=IN IP4
a=sendrecv
3:
m=audio 43538 RTP/AVP 0 8 18 96 97
c=IN IP4
How can I achieve this?
The easiest way would be to split on the regex
(?m)^(?=m=).Explanation:
You need to tell us which regex engine you’re using so we can provide a working code sample.
In JavaScript, the mode modifiers need to go outside of the regex, so you get: