Sam Aniston Sam Aniston - 3 months ago 11
Javascript Question

JavaScript regex get all numbers but exlude all between brackets

I have string:

1234 [ blabla 101112 ] 67890 [113141516 ] bla171819 212123

I need to get only numbers inside of space symbols (or maybe start/end of line), but I don't need to get any symbols, that placed between square brackets [ ] in my string now.
The correct result should be:
1234 AND 67890 AND 212123

I've tried to write such JavaScript regex:


but it is wrong, it seems like positive lookahead has more priority than negative lookahead.


May be you can do as follows;

var str = "1234 [ blabla 101112 ] 67890 [113141516 ] bla171819 212123",
 result = str.match(/\d+(?=\s*\[|$)/g);


Regular expression visualization

Debuggex Demo