PHP uses regular expressions to extract character examples in string brackets, Parentheses (), brackets [], and braces {}. For more information, see
PHP uses regular expressions to extract character examples in string brackets, Parentheses (), brackets [], and braces {}. For more information, see
The Code is as follows:
$ Str = "Hello <我> (Love) [BEIJING] {Tiananmen Square }";
Echo f1 ($ str); // return hello
Echo f2 ($ str); // return me
Echo f3 ($ str); // returns 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) indicates that this character is not captured. It seems that PHP does not support replacing characters with parentheses.
Otherwise, you can view the loop as nested, and then perform loop matching.
PS2: Huanshi :(?!) (? = )(? If there is a smaller number, match on the right, and if not, match on the left. Exclamation points indicate unequal, and equal signs indicate equal.
PS3: all of them have been verified by the validators. For more information about the validators, see references.