JavaScript RegExp \d meta character

Definition and usage

\d Match numbers from 0 to 9 using meta characters.

Example

Global search for numbers:

let text = "Give 100%!";
let pattern= /\d/g;

Try it yourself

Syntax

new RegExp("\\d")

Or abbreviated as:

/\d/

Syntax with modifiers

new RegExp("\\d", "g")

Or abbreviated as:

/\d/g

Browser support

/\d/ It is an ECMAScript1 (ES1) feature.

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Supports Supports Supports Supports Supports Supports

Regular expression search methods

In JavaScript, regular expression text search can be completed using different methods.

UsagePattern (pattern)As regular expressions, these are the most commonly used methods:

example description
text.match(pattern) 字符串方法 match()
text.search(pattern) 字符串方法 search()
pattern.exec(text) RexExp 方法 exec()
pattern.test(text) RexExp Method test()