0

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?

georg
  • 211,518
  • 52
  • 313
  • 390
LongHike
  • 4,016
  • 4
  • 37
  • 76
  • When you repeat a capturing group, only the last capture is kept. See http://www.regular-expressions.info/captureall.html – Amal Murali Nov 28 '14 at 09:07

1 Answers1

0
^(?!flex_table\b).*$|(\[(\w+)\]\[(\d+)\])

Try this.Grab the captures.See demo.

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

vks
  • 67,027
  • 10
  • 91
  • 124
  • Wow, it's really working. It humbles me that my own efforts didn't even come close to any kind of solution path and yours looks so elegant. Thank you very much! – LongHike Nov 28 '14 at 09:25
  • This is killing me, but how would I need to change the expression to also grab the string in the space for flex_table? – LongHike Nov 28 '14 at 10:54
  • @LongHike what d testt string – vks Nov 28 '14 at 11:27