Regular Expressions Character classes Non-digits matching (negated character class)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

[^0-9]

This will match all characters that are not ASCII digits.

If Unicode digits are also to be negated, the following expression can be used, depending on your flavor/language settings:

[^\d]

This can be shortened to:

\D

You may need to enable Unicode character properties support explicitly by using the u modifier or programmatically in some languages, but this may be non-obvious. To convey the intent explicitly, the following construct can be used (when support is available):

\P{N}

Which by definition means: any character which is not a numeric character in any script. In a negated character range, you may use:

[^\p{N}]

In the following sentences:

  1. Hi, what's up?

  2. I can't wait for 2017!!!

The following characters will be matched:

  1. ,, , ', ?, the end of line character and all letters (lowercase and uppercase).

  2. ', , !, the end of line character and all letters (lowercase and uppercase).



Got any Regular Expressions Question?