tags:

views:

120

answers:

2

Hi,

I have a regular expression for matching URIs:

eg: preg_match("/^my\/uri\//i", "my/uri/whatever");

which I use for routing: eg: "http://www.mywebsite.com/my/uri/page.html" will match the above (with the protocol/host removed of course)

now I was wondering if there was any way to evaluate the regular expression into the most general URI that will match: eg: "my/uri/"

Thanks

A: 

maybe if you can tell the original problem that leads you into this dead end someone can give a twist on the situation.
i've made my self a routing algoritm and i just use and explode on '/' and works very nicelly, something like magento or zend does it, registering path controllers or routers and linking them.
maybe your original problem can be solve without need to write a regexp engine with php.

useless
+1  A: 

I didn't understand what you actually want.

This code might be what you need:

$general_uri = 'my/uri/';
$regex = '/^' . preg_quote($general_uri) . '/i';

If you want reverse of the above code:

$regex = '/^my\/uri\//i';
$general_uri = str_replace('\\', '', preg_replace('/^\/\^(.*)\/i?$/', '$1', $regex));

However above code will not work on complicated regexes.

Farhadi
I guess that will work for simple regex. Thanks
Petah