Cool Regex Win-of-the-week
Posted: Thu, 10 September 2009 | permalink | No comments
I just had a need to match a regex where there were two occurances of the same string, and it would be really, really nice to make sure that both occurances were actually the same (rather than both being different strings that just happen to match the same regex). Just to be funny, I tried this:
/([a-z0-9\.-]+).*\1/
And knock me down with a feather, it worked! This is using Ruby's regex handling, but I'd be stunned if Perl didn't also handle this case.
The world just got a little bit awesomer today.
Post a comment
All comments are held for moderation; markdown formatting accepted.