Andres Felipe
Andres Felipe

Reputation: 4330

Why this preg_match evaluate spaces?

i have this preg_match, but i can't understand why, it is evaluating for spaces:

preg_match('/[\'^\"^\0-9^£$%&*()!·¢∞&÷“≠´}{@#~?><>,|=_+¬-]/'

i want to verify if there is any of those characters but allowing the spaces, sorry i am no so good with regex, i know that the space in regex is \s, thank you in advance.

Upvotes: 0

Views: 41

Answers (1)

user3783243
user3783243

Reputation: 5224

The \0-9 is not making a range of numbers. Use \d or 0-9, without the backslash. You also don't need to escape the double quote, and you only need to list each character once, > and ^ were listed more than once. If you were trying to pair them with the preceding character that won't work. You could use an optional grouping for that (this|that). Every character in a character class is individual with the exception of ranges (and because of that be careful with the -).

This should function as you expect your current regex to:

[\'^"0-9£$%&*()!·¢∞&÷“≠´}{@#~?<>,|=_+¬-]

Upvotes: 1

Related Questions