troubleshooting Question

Regular Expression - Matching HTML INPUT value - with no double quotes around it

Avatar of aaron900
aaron900 asked on
Regular ExpressionsC#
6 Comments2 Solutions490 ViewsLast Modified:
So I guess this is why everybody advises against matching HTML with regexs ;-) Unfortunately, with my app, I don't have a choice to read it from the DOM... I have an IE add-on reading HTML and passing it on to me to parse it server-side, and I'm seeing some things I've never seen. For some reason IE is at times returning values and names without double quotes around them.

<INPUT onchange=setdirty(0); value=555-555-1212 type=text name=phn_Agent_Phone_CF15>
<INPUT onchange=setdirty(0); value=test@test.com type=text name=email_Agent_Email_CF15>
<INPUT onchange=setdirty(0); value=1/1/2010 type=text name=dt_HFTrip_from_date_CF15>

I don't need one gigantic regex that can capture all values - need one that I can define the name in, and get the value. But the trick is, sometimes the name has quotes around it, sometimes it doesn't (I made this optional for the name, see below). But the value of the tag is really throwing me off. I can't seem to define in my capture a way to tell it that if it has no double quotes around the value, to go ahead and allow it, but stop capturing after the first space it encounters.

One regular expression, that can capture the value of of an HTML INPUT tag based on the name I define it, with double quotes being totally optional, would be awesome, but not necessary... I have a regular expression that works great when there are quotes around it, but I can't seem to get the one to work that has no double quotes around the value.

Here's what I'm trying for the email address, *when it has double quotes* (it works great):
<input [^>]*(?<=name="?email_Agent_Email_CF15"?[^<]*)(?<=value="([^"]*)"[^<]*)>

But no matter what I try for accommodating for ones with no quotes, just stopping at the first space, I always end up getting extra markup that shouldn't be returned.

Your help is GREATLY appreciated - thanks!


ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros