• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Regex Help

Brent W

Well-known member
#1
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
#2
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"