-1

My regular expression matches the string in the last occurrence of VALUE. How do I tweak my RegEx to match the string only in the first occurrence after a certain string?

Regex: NAME="var1".+VALUE="(.+)" Text:

<INPUT TYPE="HIDDEN" NAME="var1" VALUE="value that i want to be captured"/><INPUT TYPE="HIDDEN" NAME="var2" VALUE="value2"/><INPUT TYPE="SUBMIT" VALUE="value that is captured, but i don't want to be captured" />

My current RegEx captures the value: "value that is captured, but i don't want to be captured"

Kik
  • 73
  • 3

1 Answers1

0

To answer your question

You need to make your regex lazy Regex quantifiers

NAME="var1".+?VALUE="(.+?)"

Demo

Since this is HTML you must use some HTML parser for getting result, not sure which language you're working on but most of language do have HTML parse if not than there are libraries to help you with it

Code Maniac
  • 37,143
  • 5
  • 39
  • 60