如何在匹配 REGEX 后获取文本 [英] How to get text after the match REGEX
本文介绍了如何在匹配 REGEX 后获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我有字符串my home"和正则表达式:$reg = "/hom/".我正在努力找出如何在比赛结束后获取文本(直到单词结束),在这种情况下,我正在寻找e".
I have string "my home" and regex: $reg = "/hom/" for example. I'm struggling to find out how can I get text after the match (until the end of word), in this case I'm looking for 'e'.
另一个例子:
$string = 'soulful';$reg = '/soul/';
=>>> 我需要满".提前致谢.
=>>> I need 'ful'. Thank you in advance.
推荐答案
您可以使用:
$str = 'soulful';
$reg = '/soul(\w+)/';
if ( preg_match($reg, $str, $m) )
print_r ($m);
输出
Array
(
[0] => soulful
[1] => ful
)
这篇关于如何在匹配 REGEX 后获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文