Reputation: 1932
I have a regular expression in Java: [^a-zA-Z0-9.-_]
How to form this regular expression from java
to php
?
Upvotes: 0
Views: 61
Reputation: 4996
It's exactly the same but you might need to put delimiters around it, e.g. parenthesis:
([^a-zA-Z0-9._-])
See the little difference moving the minus to the end. That is because [.-_]
matches ./0...9:;<=>[email protected][\]^_
. I guess you're not looking for the negation of this as you had already 0-9 and A-Z covered.
Upvotes: 0
Reputation: 89557
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
Upvotes: 0
Reputation: 254944
In php (PCRE) this regular expression looks like
[^a-zA-Z0-9.-_]
Yep, it's exactly the same
Upvotes: 3