PHP uses regular expressions to extract character examples in angle brackets <>, parentheses (), square brackets [], and curly brackets {} in a string. Friends who need it can refer to the following
The code is as follows:
$str="Hello(love)[Beijing]{Tiananmen}";
echo f1($str); //return hello
echo f2($str); //return to me
echo f3($str); //return love
echo f4($str); //Return to Beijing
echo f5($str); //Return to Tiananmen
function f1($str)
{
$result = array();
preg_match_all("/^(.*)(?:<)/i",$str, $result);
return $result[1][0];
}
function f2($str)
{
$result = array();
preg_match_all("/(?:<)(.*)(?:>)/i",$str, $result);
return $result[1][0];
}
function f3($str)
{
$result = array();
preg_match_all("/(?:()(.*)(?:))/i",$str, $result);
return $result[1][0];
}
function f4($str)
{
$result = array();
preg_match_all("/(?:[)(.*)(?:])/i",$str, $result);
return $result[1][0];
}
function f5($str)
{
$result = array();
preg_match_all("/(?:{)(.*)(?:})/i",$str, $result);
return $result[1][0];
}
PS: (?: character) means not to capture this character. It seems that PHP does not support changing characters into brackets.
Otherwise, you can nest the lookaround and loop the matching.
PS2: Look around: (?!) (?=) (?
If there is a less than sign, it will be matched on the right side, and if there is not, it will be matched on the left side. The exclamation mark indicates inequality, and the equal sign indicates equality.
PS3: All have been verified by the authenticator. For the authenticator, see the reference materials.