php中正则表达式的分组和命名
2017-01-05 15:07
274 查看
示例1:
示例2:
$regex='#^/type/(\w+)/id/([0-9]+)$#i'; $str='/type/topic/id/11'; if(preg_match($regex,$str,$matches)){ var_export($matches); }
result: array ( 0 => '/type/topic/id/11', 1 => 'topic', 2 => '11', )
示例2:
$regex='#^/type/(?<type>\w+)/id/(?<id>[0-9]+)$#i'; $str='/type/topic/id/11'; if(preg_match($regex,$str,$matches)){ var_export($matches); }
result: array ( 0 => '/type/topic/id/11', 'type' => 'topic', 1 => 'topic', 'id' => '11', 2 => '11', ) )
相关文章推荐
- 正则表达式学习之回溯与固态分组/php
- PHP里的正则表达式分组
- 正则表达式中命名分组
- php学习第四章:正则表达式(四)匹配规则:分组、环视(零宽断言和负向零宽断言)
- 正则表达式 分组命名 替换
- 详解python里使用正则表达式的分组命名方式
- 正则表达式中命名分组
- 正则表达式--命名分组
- python里使用正则表达式的分组命名方式
- PHP正则表达式的效率 回溯与固化分组
- php正则表达式的分组捕获
- PHP实现正则表达式分组捕获操作示例
- 在php中用正则表达式实现最短匹配
- 利用正则表达式过滤html代码(PHP)
- 正则表达式-分组构造
- php的正则表达式
- PHP正则表达式典型应用三例
- C#中的正则表达式的分组应用
- php半小时精通正则表达式