Calling all regex gurus

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

Moderator: General Moderators

Post Reply
LeMerovingian
Forum Newbie
Posts: 1
Joined: Wed Nov 15, 2006 9:00 am

Calling all regex gurus

Post by LeMerovingian »

having a tough time trying to figure this one:

here are the samples i would like to match on (match items in bold)....

http://www.mydomain.com/[b]somepage[/b] (basically anything that comes after the "/" slash)
http://www.mydomain.com/[b]somepage[/b]

However, I don't want to match anything with a .php extension or with nothing after the "/". ie...

http://www.mydomain.com
http://www.mydomain.com/index.php
http://www.mydomain.com
http://www.mydomain.com/index.php
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Next time use a subject that says something about your actual problem...

[^abc] would match everything exepct a, b or c.. I presume you can take it from here...
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Post by kaisellgren »

Well I would do the following:

Code: Select all

$str = "http://www.sdfsdf.com/dfssdf.php";
$ending = preg_replace("~(?:(?:(?://)?.*?/))~","",$str);
if (preg_match("~\.~",$ending))
 echo "no return";
else
 echo "the returnable variable value is $ending";
Post Reply