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?

Chris D

XenForo developer
Staff member
The expression would look like this:

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

Example in 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"