Regex - match a single HTML element value tag

I've got what I need to do what I need to do... but I'm curious..

Consider: <input type="text" name="first1"> <input name="first2" value=""> and <input name="last" value="Smith" />

I can match just the HTML input element for the name "last" with: (<input [^>]*(?<=name="last"[^<]*)>)

And once I have that, I can match another regular express for value="(.*?)"

But is there any way to combine the capturing of the value with the capturing of the element? What makes it more difficult is that I don't know if the "value" tag will be to the left, or to the right of the "name" tag... is there a way to consistently bring that value into say match #2, using only one regular expression?
aaron900Asked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
Try:
(<input [^>]*(?<=name="last"[^<]*)(?<=value="([^"]*)"[^<]*)>)

Open in new window

0
 
käµfm³d 👽Commented:
P.S.

The 2nd capture group is in the 2nd lookbehind.
0
 
aaron900Author Commented:
Holy snikies - wow! EXACTLY what I needed! I will have to look closely to figure out exactly what's going on.

Thanks so much for the awesome and quick response!!!
0
 
käµfm³d 👽Commented:
I will have to look closely to figure out exactly what's going on.

Feel free to post back for a clarification of the pattern's behavior. I thought you might be interested in evaluating it for yourself, but I'm certainly OK to provide an explanation.

NP. Glad to help  = )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.