mancuoj / TIL

今天学了什么,记录在 issue 中
0 stars 0 forks source link

Regex 101 #4

Open mancuoj opened 2 months ago

mancuoj commented 2 months ago

Regex, aka Regular Expression. It helps to match, find or manage text.

mancuoj commented 2 months ago

Basic Matchers

The character or word we want to find is written directly.

mancuoj commented 2 months ago

Dot . : Any Character

The period . allows selecting any character, including special characters and spaces.

mancuoj commented 2 months ago

Character Sets [abc]

If one of the character in a word can be various characters, we write it in square brackets [] with all alternative characters.

Negated Character Sets [^abc]

mancuoj commented 2 months ago

Letter Range [a-z]

To find letters in the specified range, the starting letter and the ending letter are written in square brackets [] with dash between them -. It is case-intensive.

Number Range [0-9]

mancuoj commented 2 months ago

Asterisk *

We put an asterisk * after a character to indicate that the character may either not match at all or can match many times.

Plus Sign +

To indicate that a character can occur one or more times, we put a plus sign + after a character.

Question Mark ?

To indicate that a character is optional, we put a ? question mark after a character.

mancuoj commented 2 months ago

Curly Braces

To express a certain number of occurrences of a character, at the end we write curly braces {n} along with how many times we want it to occur.

To express at least a certain number of occurrences of a character, immediately after the character we write at least how many times we want it to occur in a row followed by a comma , and wrapped inside curly braces {n, }.

To express the occurrence of a character in a certain number range, we write curly braces {x,y} for the inclusive interval.