PHP preg_match-只匹配一个完全独立的关键字?
如何匹配完全独立的关键字 例如,我只想在如下字符串中匹配PHP preg_match-只匹配一个完全独立的关键字?,php,regex,preg-match,Php,Regex,Preg Match,如何匹配完全独立的关键字 例如,我只想在如下字符串中匹配hello /say/hello/world/ /say/hello/ 但是不是在这些 /say/helloworld/ /say/hello-world/ /say/hello+world/ /say_hello_world/ 到目前为止,这种模式 var_dump(preg_match('~.*?(?=hello)~i', $string)); // int 1 这和他们所有人都一样 我只希望/something/hello/wo
hello
/say/hello/world/
/say/hello/
但是不是在这些
/say/helloworld/
/say/hello-world/
/say/hello+world/
/say_hello_world/
到目前为止,这种模式
var_dump(preg_match('~.*?(?=hello)~i', $string)); // int 1
这和他们所有人都一样
我只希望
/something/hello/world/
为int 1
-可能吗?将前瞻更改为同时包含斜杠:
~.*?(?=/hello/)~i
代码:
~.*?(?=/hello/)~i
代码:
~.*?(?=/hello/)~i
代码:
~.*?(?=/hello/)~i
代码:
(?<=/)hello(?=/)
(?您可以将此正则表达式与lookarounds一起使用:
(?<=/)hello(?=/)
(?您可以将此正则表达式与lookarounds一起使用:
(?<=/)hello(?=/)
(?您可以将此正则表达式与lookarounds一起使用:
(?<=/)hello(?=/)
(?我收到此错误警告:preg_match():无结尾分隔符“”。”在中找到,然后它不匹配/say/hello/
@tealou:我没有在答案中包含分隔符。您需要使用~.*(?=/hello/)~i
@tealou:请查看更新后的答案;我添加了代码和一个工作演示。我在
中找到此错误警告:preg_match():无结尾分隔符“.”,然后它不匹配/say/hello/
@tealou:答案中没有包含分隔符。您需要使用~.*(?=/hello/)~i
@tealou:请查看更新后的答案;我添加了代码和一个工作演示。我在
中找到此错误警告:preg_match():无结尾分隔符“.”,然后它不匹配/say/hello/
@tealou:答案中没有包含分隔符。您需要使用~.*(?=/hello/)~i
@tealou:请查看更新后的答案;我添加了代码和一个工作演示。我在
中找到此错误警告:preg_match():无结尾分隔符“.”,然后它不匹配/say/hello/
@tealou:答案中没有包含分隔符。您需要使用~.*(?=/hello/)~i
@tealou:请查看更新后的答案;我添加了代码和一个工作演示。我收到此错误警告:preg_match():未知修饰符'h'。
然后它不匹配/say/hello/
我收到此错误警告:preg_match():未知修饰符“h”在..
中,则它不匹配/say/hello/
我收到此错误警告:preg_match():未知修饰符“h”在..
中,则它不匹配/say/hello/
我收到此错误警告:preg_match():未知修饰符“h”在..
中,则它不匹配/say/hello/