Page 1 of 1
preg_match
Posted: Thu Oct 13, 2005 6:44 pm
by igeoffi
if i have a pattern for preg_match, would it be possible to figure out the string from the pattern
example:
Code: Select all
if(preg_match('/\\A(\\w{6})-\\w{6}-\\w{6}\\z/', $variable, $v2)
how would i figure out what string matches this pattern?
Posted: Thu Oct 13, 2005 6:51 pm
by Jenk
That given pattern would match (at a glance) the following:
"\A\wwwwww-\wwwwww-\wwwwww\z"
I think, as I am still new to regex.
EDIT: Tested, no it doesn't.
Anyway, you have escaped the slashes so it wouldn't be looking for words I would have thought?
Posted: Thu Oct 13, 2005 7:00 pm
by redmonkey
it means the complete string must be..
Any 6 word characters followed by a dash followed by any 6 word characters followed by a dash followed by any 6 word characters
And that must be the complete string.
Posted: Thu Oct 13, 2005 7:01 pm
by Jenk
But he has escaped the slashes..
Posted: Thu Oct 13, 2005 7:03 pm
by redmonkey
Correct, that's to stop PHP interpreting/stripping the slashes that should be getting passed to the regex engine.
Posted: Thu Oct 13, 2005 7:32 pm
by igeoffi
Any 6 word characters followed by a dash followed by any 6 word characters followed by a dash followed by any 6 word characters
And that must be the complete string.
what part of it tells me that its
any character
and im assuming that
is that part that tells me that its 6 characters?
and reading from the php website (which im still confused)
$variable in my first post would be the string that is checked to see if it matches the pattern
and $v2
would be i have no clue
and what does the a and z mean in it?
or is it jus gibberish?