bbholzbb
bbholzbb

Reputation: 1932

form java regex to php regex

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

Answers (3)

M8R-1jmw5r
M8R-1jmw5r

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

Casimir et Hippolyte
Casimir et Hippolyte

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

zerkms
zerkms

Reputation: 254944

In php (PCRE) this regular expression looks like

[^a-zA-Z0-9.-_]

Yep, it's exactly the same

Upvotes: 3

Related Questions