Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does \d in Javascript regex do?

What does \d do in this example?

/Chapter (\d+)\.\d*/
like image 825
DarkLightA Avatar asked Dec 27 '10 19:12

DarkLightA


People also ask

What does \d do regex?

Decimal digit character: \d \d matches any decimal digit. It is equivalent to the \p{Nd} regular expression pattern, which includes the standard decimal digits 0-9 as well as the decimal digits of a number of other character sets. If ECMAScript-compliant behavior is specified, \d is equivalent to [0-9].

What does the metacharacter \d means in regular expression?

The \D metacharacter matches non-digit characters.

What is \b in regex JavaScript?

The RegExp \B Metacharacter in JavaScript is used to find a match which is not present at the beginning or end of a word. If a match is found it returns the word else it returns NULL.


3 Answers

In what context?

In a regular expression, it matches a digit (0-9).

Edit, according to your comment:

It matches any string starting with Chapter, followed by digits, then a dot, then a number of digits. Like Chapter 1.0 and Chapter 12.01.

like image 67
alexn Avatar answered Oct 14 '22 05:10

alexn


In a regex it means digits 0-9

\d Digits 0 through 9 /H\d/ matches "H3"

like image 36
Mark Baijens Avatar answered Oct 14 '22 06:10

Mark Baijens


If it is in a regular expression (match or replace or split) or a /.../ string then it probably means match any digit 0-9. Please provide the code you see it in so we can be sure.

like image 2
700 Software Avatar answered Oct 14 '22 05:10

700 Software