The Wayback Machine - https://web.archive.org/web/20240623061026/https://www.geeksforgeeks.org/javascript-regexp-d-metacharacter-2/
Open In App

JavaScript RegExp \D Metacharacter

Last Updated : 11 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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]. 

Syntax: 

/\D/ 
or
new RegExp("\\D")

or



Syntax with modifiers:

/\D/g 
or
new RegExp("\\D", "g")

Examples of RegExp \D Metacharacter in JavaScript

Example 1: This example searches the non-digit characters in the whole string. 

Javascript




function geek() {
    let str1 = "GeeksforGeeks@_123_$";
    let regex4 = /\D/g;
    let match4 = str1.match(regex4);
 
    console.log("Found " + match4.length
        + " matches: " + match4);
}
geek()


Output

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

Example 2: This example searches the non digit characters in the string. 

Javascript




function geek() {
    let str1 = "Geeky@128";
    let regex4 = new RegExp("\\D", "g");
    let match4 = str1.match(regex4);
 
    console.log("Found " + match4.length
        + " matches: " + match4);
}
geek()


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

Supported Browsers: The browsers supported by RegExp \D Metacharacter are listed below:

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer

We have a complete list of Javascript RegExp expressions, to check those please go through this JavaScript RegExp Complete Reference article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.  



Previous Article
Next Article

Similar Reads

JavaScript RegExp \S Metacharacter
The RegExp \S Metacharacter in JavaScript is used to find the non-whitespace characters. The whitespace character can be a space/tab/new line/vertical character. It is the same as [^\t\n\r]. Syntax: /\S/ or new RegExp("\\S")Syntax with modifiers: /\S/g or new RegExp("\\S", "g")Example 1: This example matches the non-whitespace characters. C/C++ Cod
1 min read
JavaScript RegExp . Metacharacter
The RegExp . Metacharacter in JavaScript is used to search single characters, except line terminator or newline. Syntax: /regexp./ or new RegExp("regexp.") Syntax with modifiers: /regexp./g or new RegExp("regexp.", "g") Example 1: This example searches the words whose starting character is "A" and ending character is "C" with only one character in
2 min read
JavaScript RegExp \W Metacharacter
The RegExp \W Metacharacter in JavaScript is used to find the nonword character i.e. characters which are not from a to z, A to Z, 0 to 9. It is the same as [^a-zA-Z0-9]. Syntax: /\W/ or new RegExp("\\W") Syntax with modifiers: /\W/g or new RegExp("\\W", "g") Example 1: This example searches the non words characters. C/C++ Code function geek() { le
2 min read
JavaScript RegExp \w Metacharacter
The RegExp \w Metacharacter in JavaScript is used to find the word character i.e. characters from a to z, A to Z, 0 to 9. It is the same as [a-zA-Z_0-9]. Syntax: /\w/ or new RegExp("\\w") Syntax with modifiers: /\w/g or new RegExp("\\w", "g") Example 1: This example searches the lowercase characters, uppercase characters, and underscore. C/C++ Code
2 min read
JavaScript RegExp \b Metacharacter
The RegExp \b Metacharacter in JavaScript is used to find a match at the beginning or end of a word. If a match is found it returns the word else it returns NULL. Syntax: /\b/ or new RegExp("\\b") Syntax with modifiers: /\b/g or new RegExp("\\b", "g") Example 1: This example matches the word "GeeksforGeeks" at the beginning of the string. C/C++ Cod
2 min read
JavaScript RegExp \B Metacharacter
The RegExp \B Metacharacter in JavaScript is used to find a match that is not present at the beginning or end of a word. If a match is found it returns the word else it returns NULL. Syntax: /\B/ or new RegExp("\\B") Syntax with modifiers: /\B/g or new RegExp("\\B", "g") Example 1: This example matches the word "for" which is not present at the beg
2 min read
JavaScript RegExp \n Metacharacter
The RegExp \n Metacharacter in JavaScript is used to find the newline character. If it is found it returns the position of the character else it returns -1. Syntax: /\n/ or new RegExp("\\n") Example 1: This example searches for the newline character in the string. C/C++ Code function geek() { let str1 = "GeeksforGeeks@_123_$"; let regex4
2 min read
JavaScript RegExp \f Metacharacter
The RegExp \f Metacharacter in JavaScript is used to find the form feed character (form feed is a page-breaking ASCII control character). If it is found it returns the position else it returns -1. Syntax: /\f/ or new RegExp("\\f") Example 1: This example searches for the form feed character in the string. C/C++ Code function geek() { let str1 =
2 min read
JavaScript RegExp \r Metacharacter
The RegExp \r Metacharacter in JavaScript is used to find the carriage return character (Carriage return means to return to the beginning of the current line without advancing downward). If it is found it returns the position else it returns -1. Syntax: /\r/ or new RegExp("\\r") Example 1: This example searches for the carriage return character in
2 min read
JavaScript RegExp \t Metacharacter
The RegExp \t Metacharacter in JavaScript is used to find the tab character. If it is found it returns the position else it returns -1. Syntax: /\t/ or new RegExp("\\t") Example 1: This example searches for the tab character in the string. C/C++ Code function geek() { let str1 = "GeeksforGeeks@_123_$"; let regex4 = /\t/; let match4 = str1
2 min read
three90RightbarBannerImg