holy regex batman
| Comments- | Posted in
- regex
last week i was getting real frustrated with some regex madness. i had a string here:
>Status Updates</b><br /><form action="home.aspx" method="post">
<input type="hidden" name="post_form_id" value="blah" />Tim is testing....
and was needing to get the value attribute out. i was using the regex pattern of:
\"post_form_id\"\svalue=\"(?<formId>(.*))\"
and it was giving me the starting point but also the rest of the string at the end. argh! i am not an advanced regex guru and was getting pretty frustrated about the solution. luckily some other people with mad skillz came to my rescue (thanks dino and zain).
taking the modified pattern to:
"\"post_form_id\"\\svalue=\"(?<formId>(?:[^\"]*))\""
gave me the specific outcome i expected and the capture into my group that i needed. so i was happy. the explanation of why the first pattern wasn't working was because my ".*" was slurping up all the good stuff including all text until the last double-quote. to my feeble brain it didn't make too much sense as when i look at the pattern it looked good, but i digress.
anyhow, in this exercise i learned that zain had a webcast series on regex. so if you want to be immersed in a series of non-readible characters with all sorts of brackets, head on over to zain's world for his webcast series all about regex.
Please enjoy some of these other recent posts...
Comments