Regex - match a single HTML element

Hi, just can't seem to get this right...

I have a string that has multiple HTML elements in it from another site, and having trouble matching exactly what I need.

Consider: <input type="text" name="first"> <input name="first2" type="text"> <input type="text" name="last" onclick="runFunction()" />

There's a lot of inconsistency in the dynamic code that generates this, I can't assume the order of anything will be consistent between pages.

My goal is to match just the "last" field - everything between <input and />... trying to accomplish with: (<input.*?name="last".*? />) - but that matches two groups - both are the entire string (finding the first occurence of <input, to the last occurence of >

Without putting them all into an array, or looping through the results, how can I match just that single HTML element into just one capture group?

Thanks so much!
Who is Participating?
käµfm³d 👽Commented:
Try this:
(<input [^>]*(?<=name="last"[^<]*)>)

Open in new window

aaron900Author Commented:
Thank you so much - I was reading your article on lookarounds and just couldn't get it right. So awesome!
käµfm³d 👽Commented:
NP. Glad to help  : )


Thanks for letting me know that people are actually reading it   = )
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.