JavaScript RegExp D( nondigit characters) Metacharacter (original) (raw)

Last Updated : 10 Dec, 2024

The **RegExp \D Metacharacter in JavaScript is used to search **non-digit characters i.e all the characters except digits. It is the same as [^0-9].

JavaScript `

let str = "a1234g5g5"; let regex = /\D/g; let match = str.match(regex);

console.log("Found " + match.length + " matches: " + match);

`

Output

Found 3 matches: a,g,g

**Syntax:

/\D/

**Example 1: Searches the non-digit characters in the whole string.

JavaScript `

let str = "GeeksforGeeks@123$"; let regex = /\D/g; let match = str.match(regex);

console.log("Found " + match.length + " matches: " + match);

`

Output

Found 17 matches: G,e,e,k,s,f,o,r,G,e,e,k,s,@,,,$

**Example 2: Searches the non digit characters in the string.

JavaScript `

let str = "Geeky@128"; let regex = new RegExp("\D", "g"); let match = str.match(regex);

console.log("Found " + match.length + " matches: " + match);

`

Output

Found 6 matches: G,e,e,k,y,@

Difference Between \d and \D

Character Type \d Matches \D Matches
Digits (0-9) Yes No
Digits (0-9) No Yes
Symbols (@, #, $, etc.) No Yes
Whitespace (spaces, tabs, newlines) No Yes