Copy Code code as follows:
$str = "Hello < i > (love) [Beijing]{Tiananmen Square}";
Echo F1 ($STR);//return Hello
echo f2 ($STR);//Back to Me
Echo F3 ($STR);//Back to Love
Echo f4 ($STR);//Back to Beijing
Ech o 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) indicates that this character is not captured. It seems that PHP does not support converting characters to parentheses.
Otherwise, you can nest around, and you can loop through it.
PS2: Look around: (?!) (?=) (? <!) (? <=)
There is a match on the right of the less than number, no match on the left. Exclamation marks are unequal, equals numbers represent equality.
PS3: Verified by validator, see Resources for Validator.
PS: Here again for you to provide 2 very convenient regular expression tools for your reference to use:
JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript
Regular expression online generation tool:
Http://tools.jb51.net/regex/create_reg