Regular learning


Regular learning


Character class []

An object that conforms to certain characteristics
/[ABC] / means to match one of ABC

  • The reverse class [^] is enclosed in brackets^

Example: [^ A] is to match characters that are not a

Range class [A-Z]

It can match any character in A-Z

Predefined Class

  • Predefined characters:

\D is a number

  • Boundary character

\B is the boundary
^It means to match the beginning outside
$means to match the ending


{n} The length of the matching string is n

The minimum length of {m, n} matching string is m and the maximum length is n
The minimum length of {m,} matching string is m and the maximum is infinite
The minimum length of {0, n} matching string is empty and the maximum length is n
+Occurrence times > = 1
*Current frequency > = 0
? Occurrence times 0 or 1
. can match any character except the newline character in the white space character

Greedy mode

  • 12345678. Replace (/ \ D {3,6} /,’x ‘) output X78

Non greedy mode

Just add a question mark after the quantifier

  • 12345678.replace(/\d{3,6}? /’x’) outputs xx78 to try the least possible match


Use () to make the quantifier most used in groups rather than the words next to it

Output xd4



Back reference

$reference (capture)

Replace December 5, 2019 with 12 / 05 / 2019

$is captured in groups

When you don’t want to capture a group, you just need to add the? :
(?: Gray). (OK) here $1 is OK

Looking forward and looking back

To learn

The original meaning of the character

To learn

Metacharacter (character representing special meaning)

To learn

XMind – Trial Version

Recommended Today

Quickly create a document project with vitepress

In fact, to develop a project is the most necessaryOperation documentThe quality of documents determines the development process, development specification and so on. For the front-end framework, the document is the most friendlyvueIt is not only the framework of Chinese people, but also the document supports Chinese. Check Vue’s official documents, andVue-Router,Vuex,Vite. It is found […]