使用正则表达式在PHP中命名捕获 [英] Named capture in PHP using regex
本文介绍了使用正则表达式在PHP中命名捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在PHP中将命名捕获与regex一起使用?谁能给我一个可行的例子?
How can I use named capture with regex in PHP? Can anyone give me a working example?
推荐答案
不适用于replace,仅对php中的匹配有用
Doesn't work with replace , only useful for match in php
$test="yet another test";
preg_match('/(?P<word>t[^s]+)/',$test,$matches);
var_dump($matches['word']);
这篇关于使用正则表达式在PHP中命名捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文