preg_match

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

Post Reply
igeoffi
Forum Newbie
Posts: 2
Joined: Thu Oct 13, 2005 6:40 pm

preg_match

Post 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?
Last edited by igeoffi on Thu Oct 13, 2005 7:33 pm, edited 1 time in total.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

But he has escaped the slashes..
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

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 »

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

Code: Select all

w{6}-
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?
Post Reply