Regex Help

Brent W

Well-known member
I want to find everything between a ^ and a / and then hold that in a variable to use elsewhere. Anyone throw me the expression for that?
 
The expression would look like this:

PHP:
/\^(.*?)\//is

The match between the ^ and / would be available in $1.

Example in PHP:

PHP:
        $haystack = '^Here is the needle/';
        $needle = preg_replace('/\^(.*?)\//is', "The Found Text is: $1", $haystack);
       
        echo $needle;

echo $needle will produce: "The Found Text is: Here is the needle"
 
Top Bottom