[Regular expression] Summary of regular rules

1. Commonly used regular rules

rule

meaning

\d

[0-9],number

\D

[^0-9], any character except numbers

\w

[0-9a-zA-Z_], numbers and letters underlined

\W

[^0-9a-zA-Z_], exclude any characters including numbers, letters and underscores

\s

[\t\v\n\r\f], whitespace symbols (including spaces, horizontal tabs, vertical tabs, line feeds, carriage returns, etc.)

\S

non-whitespace

i

case insensitive mode

g

Global match pattern

m

multi-line matching pattern

u

Wide character mode (multiple Chinese character matching)

s

Or omit line breaks (multiple lines are treated as a whole)

.

All characters except "\n" (newline character)

[\u4e00-\u9af5]

Match Chinese characters

^

start

$

Finish

\b

word boundaries

\B

non-word boundaries

wide character related

/\p{L}/gu

wide character punctuation

\p{N}/gu

wide character number

/\p{sc=Han}/to

Chinese character

Atomic group related

(?:\w)

Do not record groups

(?<dian>\.)

Atomic group alias

Use of $ symbol

$`(before matching content) $'(after matching content) $&(matching content)

affirmation

/Backing person (?=img)/, /Backing person (?!img)/

pre-assertion

(?<=I am the supporter), (?<! I am the supporter)

post-assertion

/(?<!.*good.*)人人/

global assertion

/\d+?/

Lazy matching (+ after?) is non-lazy by default

2. Commonly used regular methods

Symbols that need to be changed: period ,   parentheses (),  square brackets []     left and right slashes \/  vertical |

function

illustrate

string.matchAll(reg);

Return iterator

reg.lastIndex

Iteration properties of regular objects

reg.exec(string)

Regular object matching method

string.serch(reg);

Similar to indexof method

string.replace(reg, serch=> {…});

string.macth(reg);

Guess you like

Origin blog.csdn.net/qq_48896417/article/details/126541248