regex testing

1 view
Skip to first unread message

Matt McKeon

unread,
Aug 15, 2009, 9:50:27 PM8/15/09
to ins...@googlegroups.com
I was testing some regex patterns with isRegex and wasn't quite sure
about the results that were returned. My thought going into it was that
isRegex would return true if the *whole* $value matched the $pattern,
but that doesn't seem to be the case.

Here's my quick test http://pastebin.com/m484c4d5c
You can see where I added a check to capture the matches in preg_match
directly and compare $matches[0] to the supplied string. As per the php
docs[0] $matches[0] always returns the whole match. Maybe this test is
what should be returned instead of the return value of preg_match?

Is my thinking here correct? If not, what is the intended behavior of
isRegex?

Thanks,
Matt


[0] http://us3.php.net/manual/en/function.preg-match.php

Ed Finkler

unread,
Aug 16, 2009, 9:11:09 PM8/16/09
to ins...@googlegroups.com
isRegex simply should return true if the regex finds a match in the
input. You could give it a different regex if you wanted to make sure
the entire input was matched (start with ^, end with $, etc).

--
Ed Finkler
http://funkatron.com
Twitter:@funkatron
AIM: funka7ron
ICQ: 3922133
XMPP:funk...@gmail.com

Matt McKeon

unread,
Aug 17, 2009, 10:03:02 PM8/17/09
to ins...@googlegroups.com
hah, well I completely overlooked using ^ and $. Thanks, I'll have to go
play with that then.

Matt
Reply all
Reply to author
Forward
0 new messages