预匹配问题
如何在 preg_match 中添加字符 -
?
preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string)
但必须在最后一个之前。
字符串内。我已经尝试了这里我所知道的一切。我知道 -
需要转义。所以我尝试在各个地方逃避它,但它不起作用:(
argggg
How do I add the character -
within the preg_match?
preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string)
But it must be before the last .
within the string. I've tried just about everything I know here. I know that the -
needs to be escaped. So I tried to escape it in various places, but it's not working :(
argggg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对需要转义破折号的了解是不完整的。
它需要在字符类中进行转义,因为它在那里有特殊的含义,但是它在正则表达式的其余部分没有特殊含义,因此不需要在这里转义。
Your knowlegde that the dash needs to be escaped is incomplete.
It needs to be escaped in character classes, because it has a special meaning there, but it has no special meaning in the rest of the regex, so it needs no escaping here.