×

First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

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.

tags:


8/13/2007 11:00 AM | # re: holy regex batman
I think my fav regex ever is the one I saw on http://www.thinkgeek.com/tshirts/coder/57f0/ that had this on it: /(bb|[^b]{2})/
8/13/2007 1:39 PM | # re: holy regex batman
Another alternative is:

(?<formId>(.*?))

"*?" is the "non-greedy" version of "*"

 
Please add 5 and 1 and type the answer here:

DISCLAIMER:

The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.