Reputation: 113
I need to write a regular expression which should not allow any digits. it should allow any other characters except digits. I tried expression like :- ~[0-9]+
but it restricts everything. could you pls help me?
Upvotes: 0
Views: 108
Reputation: 17090
It is not clear what flavor of regex you need, but in the general, one of the following should work:
^[^0-9]*$
^[^\d]*$
^\D*$
^[[:^digit:]]*$
^\P{IsDigit}*$
The last two forms will work with Unicode digits.
The atom [^0-9]
matches anything but a digit; to make sure that in the whole string there are no digits, I added the markers of string start (^
) and end ($
).
If you want to match any part of a string that contains at least one character that is not a digit, replace the ^...*$
part of the regex by ...+
:
[^0-9]+
\D+
etc.
Upvotes: 2
Reputation: 109232
Try [^0-9]+
. Note that this will only prevent ASCII digits from appearing, not unicode ones.
Upvotes: 0