[英]form java regex to php regex
I have a regular expression in Java: [^a-zA-Z0-9.-_]
我在Java中有一个正则表达式:
[^a-zA-Z0-9.-_]
How to form this regular expression from java
to php
? 如何形成从
java
到php
正则表达式?
In php (PCRE) this regular expression looks like 在php(PCRE)中,此正则表达式看起来像
[^a-zA-Z0-9.-_]
Yep, it's exactly the same 是的,完全一样
it is the same for this particular regex. 此特定正则表达式是相同的。
But you can make shorter with: 但是您可以使用以下方法来缩短:
[^\w.-]
and don't forget that the - character must be placed at the last position in a character class 并且不要忘记-字符必须放置在字符类的最后位置
It's exactly the same but you might need to put delimiters around it, eg parenthesis: 完全相同, 但是您可能需要在其周围放置定界符,例如,括号:
([^a-zA-Z0-9._-])
See the little difference moving the minus to the end. 看到将负号移到末尾的微小差异。 That is because
[.-_]
matches ./0...9:;<=>?@A...Z[\\]^_
. 那是因为
[.-_]
匹配./0...9:;<=>?@A...Z[\\]^_
。 I guess you're not looking for the negation of this as you had already 0-9 and AZ covered. 我猜您不是在寻找否定的对象,因为您已经覆盖了0-9和AZ。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.