Link to home
Start Free TrialLog in
Avatar of cc01
cc01

asked on

Regex for URL

Hello,

I need to use preg_match('REGEX', $_SERVER['REQUEST_URI']) to report true when the following is true:
The REQUEST_URI string contains */clients/
[a-zA-Z0-9].php*

Where * is an infinite wildcard. The point is that it only matches URLs where it is a .php file in the /clients directory being accessed.

What is the proper REGEX value?

Thank you
Avatar of kaufmed
kaufmed
Flag of United States of America image

You can use:

^.*?/clients/[a-zA-Z0-9]\.php\b.*$

Open in new window

Avatar of cc01
cc01

ASKER

No go; that .*? should work for a / in front, correct?

This is what I am currently using:
if(preg_match('^.*?/clients/[a-zA-Z0-9]\.php\b.*$', $_SERVER['REQUEST_URI'])) {
I think you need the + after the character match. You also need start and end delimiters:

if(preg_match('|^.*?/clients/[a-zA-Z0-9]+\.php\b.*$|', $_SERVER['REQUEST_URI'])) { 

Open in new window

hi.. this is your solution

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?

use it...
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cc01

ASKER

Thank you for the solution that works and a detailed explanation as well as other advisories.
Thanks for the points and thanks for using EE, ~Ray