PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
igeoffi
Forum Newbie
Posts: 2 Joined: Thu Oct 13, 2005 6:40 pm
Post
by igeoffi » Thu Oct 13, 2005 6:44 pm
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?
Last edited by
igeoffi on Thu Oct 13, 2005 7:33 pm, edited 1 time in total.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Thu Oct 13, 2005 6:51 pm
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?
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Thu Oct 13, 2005 7:00 pm
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.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Thu Oct 13, 2005 7:01 pm
But he has escaped the slashes..
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Thu Oct 13, 2005 7:03 pm
Correct, that's to stop PHP interpreting/stripping the slashes that should be getting passed to the regex engine.
igeoffi
Forum Newbie
Posts: 2 Joined: Thu Oct 13, 2005 6:40 pm
Post
by igeoffi » Thu Oct 13, 2005 7:32 pm
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?