PHP正则表达式匹配斜杠 [英] PHP regexp match slash
本文介绍了PHP正则表达式匹配斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 regex101 测试了以下正则表达式,它在那里工作.但是,当我尝试在 preg_match 中使用它时,它不再起作用.问题是斜线:我试图转义它,但我无法让它工作.
I have the following regular expression tested at regex101 and it works there. However, when I try to use it inside the preg_match it doesn't work anymore. The problem is the slash: I tried escaping it but I can't get it working.
preg_match("/[<>\\\"'%;()&]/", "my\string");
我应该匹配的字符集是:
The set of characters that I should match are:
< > \ " ' % ; ( ) &
推荐答案
只需使用不同的分隔符:
Simply use a different delimiter:
preg_match("![<>\\\"'%;()&/]!", "my\string");
这篇关于PHP正则表达式匹配斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文