php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串
2017-11-23 09:04
651 查看
$str="你好<我>(爱)[北京]{天安门}";
echo f1($str); //返回你好
echo f2($str); //返回我
echo f3($str); //返回爱
echo f4($str); //返回北京
echo f5($str); //返回天安门
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];
}
echo f1($str); //返回你好
echo f2($str); //返回我
echo f3($str); //返回爱
echo f4($str); //返回北京
echo f5($str); //返回天安门
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];
}
相关文章推荐
- php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串
- php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串
- php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串
- php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串
- PHP正则表达式提取字符串中尖括号<>、小括号()、中括号[]、大括号{}中的字符串
- PHP中使用正则表达式提取中文实现笔记
- PHP中使用正则表达式提取中文实现笔记
- php使用正则表达式获取字符串中的URL
- 使用Java正则表达式提取字符串中的数字一例
- PHP和javascript中使用正则表达式匹配中文字符串
- PHP提取字符串中的图片地址[正则表达式]
- JS使用正则表达式获取小括号、中括号及花括号内容的方法示例
- 正则表达式:小括号、中括号、大括号的区别
- 正则表达式 括号,中括号,大括号的区别
- php正则:匹配(),{},[]小括号,大括号,中括号里面的内容
- java使用正则表达式的方法从json格式的字符串中提取需要的字符串
- [笔记]如何使用正则表达式提取字符串中的分隔元素
- 使用正则表达式提取字符串中的内容
- PHP提取字符串中的图片地址[正则表达式]