Negated decimal digit character class - \D

Q

What is abbreviation of a negated character class of all decimal digits? Does it represents any characters except decimal digits?

How to write a regular expression using a character class abbreviation to capture letters from a Canadian postal code string: L3R 9Z7?

✍: FYIcenter.com

A

The predefined abbreviation of a negated character class of all decimal digits is \D, which is the same as [^0123456789], or [^0-9]. \D will match any characters except decimal digits.

The regular expression to capture letters from a Canadian postal code is:

(\D)

\D - matches any characters except decimal digits

Click the button to test this regular expression here online:

2013-01-23, 2050👍, 0💬