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!
aaron900Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Try this:
(<input [^>]*(?<=name="last"[^<]*)>)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

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

P.S.

Thanks for letting me know that people are actually reading it   = )
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.