使用 preg_match 的简单正则表达式
我正在尝试检索该单词和分号之后的三位数。
REF: 222
我下面的代码可以工作,但效果不好,因为它从 $decoded_message 字符串中获取 3 位数字。
想要的只是在 REF: ### 一词之后获取三位数
if (preg_match("([0-9]{3})", $decoded_message, $matches)) {
echo "Match was found <br />";
echo "ref = ".$matches[0];
}
我真正
I am trying to retrieve the three digit number after this word and semi colon.
REF: 222
The code i have below works but its not good because its getting 3digit numbers from the $decoded_message string.
What i really want is only to grab three digit number after the word REF: ###
if (preg_match("([0-9]{3})", $decoded_message, $matches)) {
echo "Match was found <br />";
echo "ref = ".$matches[0];
}
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以搜索
REF: [0-9]{3}
,然后删除REF:
部分。You can search for
REF: [0-9]{3}
and then remove theREF:
part.您可以简单地使用
Afterwards 替换“REF:”,$output 中应仅包含数字。
You may simply replace "REF: " by using
Afterwards, only the number should be contained in $output.