Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use regular expressions\ d metacharacters

Shulou Source: shulou.com Published: 2022-06-02 03:56:31 10月04日 Update

I would like to share with you how to use the regular expression\ d metacharacters. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it!

Regular expression\ d metacharacter:

\ d metacharacters can match numeric characters, which is equivalent to "[0-9]".

Grammatical structure:

Constructor mode:

New RegExp (\\ d)

Object direct quantity method:

/\ d /

Browsers support:

IE browsers support this metacharacter.

Firefox browser supports this metacharacter.

Google browser supports this metacharacter.

Example code:

Example 1:

Var str= "I love antzone\ n and you 360"; var reg=new RegExp ("\\ d", "g"); console.log (str.match (reg))

The above code matches all the numbers in the string.

Example 2:

Var str= "I love antzone\ n and you 360"; var reg=/\ ddebase g; console.log (str.match (reg))

The function of this code is the same as the above code.

And in many cases, for example, in many cases, the code we copy has a number at the front, and if there are numbers in front of hundreds of lines of code, we can replace them with rules.

For example:

1 alert ("); 2 var str=" I love antzone\ n and you 360 "; 3 var reg=/\ d G; 4console.log (str.match (reg))

For example, the following rule

^ [0-9] *.

You can perfectly replace the previous number.

The above is all the contents of the article "how to use regular expressions\ d metacharacters". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Metacharacters codes regularities numbers browsers support browsing expressions examples articles content characters situations ways facets not much functions functions can be passed most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple OPPO Reno Redmi Shulou Tech Info