easy regex question... I'm just not smart enough

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
orfeus123
Forum Newbie
Posts: 2
Joined: Mon Jun 11, 2007 10:24 am

easy regex question... I'm just not smart enough

Post by orfeus123 »

Hey there

I'm trying to embed a regex variable in this URL and I can't seem to figure out which is the right one.

The link example is:

http://strategy.thesuccessleague.com/MV ... PURLPage=7

I need to find a regex variable that will replace "MVanDusen" (It's always someone's name, so the length will very from person to person)

I tried this: http://strategy.thesuccessleague.com/[:alnum:]?elqPURLPage=7

but it didn't seem to work

Any help would be beautiful

Thanks!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Look at it this way. You want everything between the "/" and the "?". The chances of them coming up more than once is very slim, and they'll always be the first match anyway.
orfeus123
Forum Newbie
Posts: 2
Joined: Mon Jun 11, 2007 10:24 am

Post by orfeus123 »

But is the [:alnum:] tag the right way to do that? Or is there a better tag for that? I'm new to regex codes so I'm a little lost in general...

Thanks a lot.

Sincerely,

The Regex Retard
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I am utterly clueless as to what an [:alnum:] tag is.

Code: Select all

#/([\w]+)\?#
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

AFAIK it's a pseudo class which is equivilent to stating [a-z0-9].

Something like that anyway, I'm not the best person to tell :)
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

[:alnum:] is a POSIX character class and not compatible with PCRE. I guess it is equivalent to [a-zA-Z0-9].

Try this regex:

Code: Select all

#http://strategy\.thesuccessleague\.com/(.*?)\?elqPURLPage=7#
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[:alnum:] is supported by PHP's PCRE last I checked.
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

feyd wrote:[:alnum:] is supported by PHP's PCRE last I checked.
Are they? Seems like you're right indeed, feyd. This surprises me. Did some test and as long as you put the POSIX character class inside a regular character class, it works (otherwise you'll get this error apparently: Compilation failed: POSIX named classes are supported only within a class).

Nice to know you can use them, however I'm not a big fan and will probably avoid them anyway.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yeah, I'm not a fan either, but I suspect they were added for compatibility of converting ereg_* to preg_* quickly for many developers since regex is a very tough subject for many.
Post Reply