-1

I am trying to read a string formatted like

<test>input</test>\n <another>input</another>

My regex works for the test tagged input, but ignores the another tagged input. If I wrap the entire regex in parenthesis and use the brackets {} to specify how many times, then it only saves the last match case. How can I catch and save all match cases?

My regex:

/([\n\s]*<([^>]+)>([^<>]*)<([^>]+)>[\n\s]*){0,}/

Result contents of match:

<test>input</test>\n <another>input</another>
<another>input</another>
another
input
/input
JustaCookie
  • 181
  • 2
  • 13

1 Answers1

1

Add a g Modifier so specify that it is global (allows for multiple results)

So change your regexp to (notice the g in the end)

/([\n\s]*<([^>]+)>([^<>]*)<([^>]+)>[\n\s]*){0,}/g
Cleared
  • 2,490
  • 18
  • 35
  • Turns out it gives me the expected result without the brackets and your suggestion. I cannot believe how simple it was. Thanks! – JustaCookie May 16 '17 at 10:42