Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use metacharacters of JavaScript regularization

Shulou Source: shulou.com Published: 2022-06-03 18:28:54 09月19日 Update

This article will explain in detail how to use metacharacters about JavaScript regularization. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Metacharacters:

Every regular expression is made up of metacharacters and modifiers

[metacharacters]-> meaningful characters between two /

Reg = / ^\ dflowers / can only be a number between 0 and 9

1. Metacharacters with special meaning

\: escape characters, translating the meaning represented by the following characters

^: start with a metacharacter

$: ends with a metacharacter

\ n: matches a newline character

. : any character except\ n

(): grouping-> dividing a large regular itself into several small regularities

X | y: X or one of y

[xyz]: one of x or y or z

[^ xyz]: any character except three

[amurz]: any character between amerz

[^ amurz]: except for any character between amurz

\ d: a character between 0 and 9\ D any character except a number between 0 and 9

\ b: a boundary character "W1 w2 w3"

\ w: any character in a number, letter, or underscore [0-9aMuz Amurz]

\ s: matches a blank character space, a tab, a feed character.

2. Quantifier metacharacters that represent the number of occurrences

*: zero to multiple occurrences

+: appear 1 to multiple times

? : zero or one occurrence

{n}: appear n times

{n,}: n to multiple times

{nrecoery m}: appear n to m times

Var reg = / ^\ d+wo\ dcharacters / 123wo234 var reg = / ^ (\ d+) wo (\ d+) $/; var reg = / ^ 0.20 $/ / ends with 0, with any character var reg = / ^\ dcards / except\ n in the middle / / can only be multiple digits console.log (reg.test ('2017')) / / true / / A simple regular verification of the mobile phone number: 11 digits, the first digit is 1 var reg = / ^ 1\ d {10} $/

Second, metacharacter application

[]

1. All characters that appear in square brackets are characters that represent their own meaning (with no special meaning).

()

1. The function of grouping: change the default priority of x | y

Var reg = / ^ 18 | 19 $/; / / those eligible are 189,119,819, 1819 var reg = / ^ (18 | 19) $/ / 188,19

1. Regular positive, negative, zero and decimal numbers of significant numbers

1), ". It may or may not appear, but once it does, it must be followed by one or more digits.

2) at the beginning, there can be + /-or not.

3) in the part of integers, one digit can be between 0 and 9, and multiple digits cannot start with 0

The rules are as follows

Var reg = / ^ [+ -]? (\ d | ([1-9]\ d +)) (\.\ d +)? $/ about "how to use metacharacters of JavaScript regularity" is shared here. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

Tags: Characters metacharacters regular between numbers representatives articles special digits meaning beginning meaning more grouping good practical valid three underscore two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Docker Redmi Microsoft MySQL