I did not understand what you really want.
This code may be what you need:
$general_uri = 'my/uri/';
$regex = '/^' . preg_quote($general_uri) . '/i';
If you want to change the code above:
$regex = '/^my\/uri\//i';
$general_uri = str_replace('\\', '', preg_replace('/^\/\^(.*)\/i?$/', '$1', $regex));
However, the above code will not work on complex regular expressions.
source
share