Regex - match starting with 'XXX' up to next occurrence

Hey my goal is to separate something like

FOO 1
 UP 2.0
 DOWN 33
 Blubber 33@11 44@55
FOO 2
 ZZZ 1.0
 X 3
 Blubber 1@4 4@5 6@22
FOO 4
 ABC D
 Blubber 33@11 44@55

into each block of FOO up to the next FOO:

FOO 1
 UP 2.0
 DOWN 33
 Blubber 33@11 44@55

and as second result

FOO 2
 ZZZ 1.0
 X 3
 Blubber 1@4 4@5 6@22

and so on..

my attempt was to get the Answers of Regex - match up to next match working for me but do not really understand how to. Must i enclose FOO in braces? (FOO) ? I Hope someone can help me out of the forest...
Sunny greetings Stefan

Upvotes: 1

Views: 1169

Answers (1)

Andy E
Andy E

Reputation: 344565

split() with positive lookahead should work:

var arr = str.split(/(?=FOO\s\d+)/);

Demo (check the console): http://jsfiddle.net/AndyE/6pxuz/

Upvotes: 4

Related Questions