Reputation: 4133
What means this regular expression
[^0-9^A-Z]
??
It non-matches any number and non-matches any upper case characters?
Upvotes: 0
Views: 81
Reputation: 490108
As it stands, it matches any single character except a digit, upper-case letter, or circumflex.
The circumflex (^
) at the beginning negates the character set. A circumflex that does not immediately follow the left bracket is interpreted as part of the character set itself. A regex of [^^]
matches any character except a circumflex.
Upvotes: 0
Reputation: 10341
When caret ^
is at the beginning of the bracketed group it means "find anything but the following items". However, when it is placed anywhere else it means "Find the caret along with the other items". Yours has both, which means "find anything but the following items (which includes the caret symbol)".
So [^A-Z0-9]
means "find any character other then capital letter or number"
Your regex is [^0-9^A-Z]
which means "find any character other then capital letter, number or a caret symbol.
As others have pointed out, you probably meant the first version, but I thought it important to note the difference between the two.
Upvotes: 1
Reputation: 9202
Correct regex: [^0-9A-Z]+
The second ^
is not needed and without a +
you're just matching one character of this type.
Note that 0-9
is the same as \d
so the best regex for this whould be be: [^A-Z\d]+
Upvotes: 1