Regular Expression javascript repeat with optional sections

88 views Asked by At

Why doesn't this javascript regexp code work? According to the documentation it should:

Here's my String for parsing (it's the rails nested form information):

flex_table[flex_rows_attributes][0][flex_cells_attributes][0][id]

What I want are these sections, which may or may not be part of the string:

flex_rows_attributes, 0, flex_cells_attributes, 0

Here's my regular expression(as I mentioned, the javascript flavour):

flex_table((\[(\w+)\]\[(\d+)\])*)

I only get back the last of the two entries, but I want them both.

Does anyone know, what I am missing here?

1

There are 1 answers

3
vks On BEST ANSWER
^(?!flex_table\b).*$|(\[(\w+)\]\[(\d+)\])

Try this.Grab the captures.See demo.

http://regex101.com/r/hQ9xT1/26