[英]What special meaning have slash “/” inside character class
In docs I can't find anything. 在文档中,我找不到任何东西。 But for pattern work properly in character class I need to escape
/
like this "\\/".
但是为了使模式在字符类中正常工作,我需要转义
/
例如"\\/".
Why I need do so? 为什么我需要这样做? Sorry for my english.
对不起我的英语不好。 I'm using PCRE and preg_match function.
我正在使用PCRE和preg_match函数。 Oh my God, sorry all and thanks for help.
噢,天哪,对不起,谢谢您的帮助。 I'm using
/
delimiters. 我正在使用
/
分隔符。
尽管/
在正则表达式本身的上下文中可能没有任何意义,但取决于编程语言, /
可能用于封装正则表达式字符串,因此需要转义。
you don't have to escape /
in [...]
你没有逃跑
/
在[...]
[/]
should work. [/]
应该可以。
and in regex, /
doesn't have special meaning. 在正则表达式中,
/
没有特殊含义。 it is literal slash. 这是字面斜线。
It isn't the regular expression itself but how it is getting parsed by the language. 它不是正则表达式本身,而是语言如何解析它。 For example in Ruby:
例如在Ruby中:
"/".match(/[/]/)
is a syntax error but: 是语法错误,但:
"/".match(/[\/]/)
will work. 将工作。
I know only one case when you should do it if you use regular expression like this one: 如果您使用正则表达式,我只知道一种情况:
/something here / something here / . /在这里/在这里/ I mean that / is start and end bound of your reg.
我的意思是/是您reg的开始和结束范围。 exr.
EXR。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.