I have a single string which looks like:
6
0 1 1 0 0
1 1 1 1 0
0 0 0 1 0
4
1 1 0 1 0
0 0 0 1 0
1 1 0 1 0
0 1 1 0 0
and would like to split into two different strings such as:
6
0 1 1 0 0
1 1 1 1 0
0 0 0 1 0
and the other string being:
4
1 1 0 1 0
0 0 0 1 0
1 1 0 1 0
0 1 1 0 0
Would I do this using regex? Or is there a better way?
note: apart from the 6 and 4 the others numbers will always be 1 or 0.
You want to split on newlines, but only when the following character(s) is only digit(s) then a newline.
Try this regex:
It uses a look ahead to assert the condition mentioned above.
Here’s some test code:
Output: