NYCPHP Meetup

NYPHP.org

[nycphp-talk] REGEXP Solution Needed

Allen Shaw allen at TwoMiceAndAStrawberry.com
Wed Sep 8 10:45:56 EDT 2010


On 09/08/2010 09:27 AM, ps at blu-studio.com wrote:
> I believe this is what I am looking for:
>
> ^http://www\\.example\\.com/events/events?.*size=[\d|\d\d^10].*
>
> If anyone can polish this more or if I am wrong, pls give a note. Thanks.
>

Good putting the carat at the front -- I forgot that in my last post.

But there are problems with your pattern:
     www\\.example matches "www\.example"
     size=[\d|\d\d^10].* matches "size=0" and "size=100000000&foo=bar", etc.

The key here is word boundaries. This will let you distinguish easily 
between "foosize" and "size", and between "10" and "10000000".

If you're on Linux or Windows, I highly recommend a little utility 
called "regex-coach" for testing regex patterns in real time.  Nothing 
like instant feedback to facilitate quick learning.  (Linux support 
stopped at version 8.5, but that's plenty good enough for what it does, 
and free-as-in-beer, too.)

Good luck,
Allen

-- 
Allen Shaw
TwoMiceAndAStrawberry.com





More information about the talk mailing list