php 正则 尖括号,php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串...
$str="你好(愛)[北京]{天安門}";
echo f1($str); //返回你好
echo f2($str); //返回我
echo f3($str); //返回愛
echo f4($str); //返回北京
echo f5($str); //返回天安門
function f1($str)
{
$result = array();
preg_match_all("/^(.*)(?:
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];
}
總結
以上是生活随笔為你收集整理的php 正则 尖括号,php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 台达plc自由口通讯_台达PLC和ABB
- 下一篇: confluent connect写出到