Regular expressions are not everywhere

Do you envy others skillfully using regular expressions while you can’t

If you want to get started with regular expressions, it’s either a long video or a book

Do you think this approach looks very marketing and uncomfortable

Yes, the rest of the list is nonsense, except for regular expressions. This may not be the whole list, but it definitely goes to rule 28, which is 20% knowledge for 80% of work scenarios. However, if you want to really master these five words, you have to be familiar with them

Regular expressions are all next to each other, all characters, and discard the idea of “nice Spaces, + signs for concatenation”

basis

What to write matches what

Cat =>I have some pets, cats, dogs and pigs. ⭕️

Cat => The cat sat on the mat. ❌

123 = > 5678912345 ⭕ ️

123 = > 12456 ❌

metacharacters

That’s what they call it on the Internet, but in my case it’s special characters

. * +?

. Matches any character except newline

. At => At is followed by a character => The cat sat on The mat. => There are three matches

C.t => c is followed by a character t => The cat sat on The mat. => there is 1 match

* Matches the preceding expression 0 or more times

[A-Z]* => Zero or more characters are matched. => The cat sat on The mat => 13 characters are matched

Yes, there are 13 matches, 1: “, “2:” he “: 3” “4:” cat “5:” “6:” sat “7:” “8:” on “9:10:” “” the” 11: “is” 12: “mat.” 13: “”.

The. Is any character, and the * is zero or more preceding characters, so the.* is any character

.\* => Any character => The cat sat on The mat => 2 match

1: “The cat sat on the mat” 2: “”

The function of + and * is the same, but * matches 0 or more characters, + matches 1 or more characters, and the rest is not described here

? So does the number, but? If yes, 0 or 1 character is matched

(a) [] {}

The contents in parentheses are considered as a whole

(c.)t => represents a character followed by c as a whole, followed by a t === c.t. Yeah, in this case it’s exactly equivalent to this => The cat sat on The mat => 1

(c | s | m) at = > according to any one of The characters in parentheses with The at = > The cat sat on The mat = > 3 matches

(c. |. A) t = > conform to The c.t or. At The two regular expressions = > The cat sat on The mat = > The cat sat on The mat = > 3 matches

[] Matches anything in parentheses

[CSM]at => cat/ SAT /mat => The cat sat on The mat => 3

[cm]at[.b] => The cat sat on The mat. Hello world => 1 And * are both characters and do not have the above special meanings

{num} is a quantifier action. It matches the characters before num. {a, b} matches the characters before B

[ld]{2,5} => Indicates the combination of 2 to 5 L, 2 to 5 D, or 2 to 5 characters. => He**llo Worldddd** DDDD! => Notice that the d is all connected together. In order to distinguish the display, the space => 3 matches => ll LDDDD DDDD

Math.max(2, 5) = 5; LDDDD = 5

^ $

^ A string that begins with a character

^T => string starting with T => The cat sat on The mat => Match 1, will match only one T => if it is ^The, will match only The3 characters

[] ^ [] ^ [] ^ [] ^ [] ^ [

[^(^T)] T => a string that does not start with T but is followed by T => The c**at** sat on ** T **he mat => matches 4

$is a string that ends with a certain character

Note that the $in [] does not have any special meaning. It simply refers to the character ‘$’

| \

| is in the code or, there is no other meaning

(c) | s | m at = > cat/sat/mat = > The cat sat on The mat = > 3 matches

\ indicates the translation character

This is a simple one for developers and won’t be repeated here

In addition to simple translation, there are also some characters to express a certain meaning

\d => digital => digital => digital => digital => digital =

\w => words => Match numbers and upper and lower case Letters => \w =>

\s => space => Matches the space character => \s =>

There are also some common ones

\n => next line => newline

\t => TAB =>, in the program to write words, generally 4 characters

\r => return => Matches carriage return

assertions

An assertion is simply a match but not a contain. This may be used more often, such as when a scene needs to match xxRES but only res instead of xx.

Assertions are divided into positive assertions and negative assertions. The so-called positive and negative assertions correspond to whether they exist or not. It is divided into antecedent assertion and antecedent assertion, respectively corresponding to whether the unwanted thing is in front or behind, for example, xxRES does not need xx as long as res needs to use antecedent assertion.

Form the format with? At the beginning, the forward assertion is = and the negative assertion is! <, and must be wrapped in ().

  • ? = : forward first assertion
  • ? <= : indicates forward after assertion
  • ? ! : negative prior assertion
  • ?

? <= forward after assertion, don’t use things before

(? <=[CSM])at => match cat/sat/mat, but not The first letter, at => The cat sat on The mat. => 3 match

? = : forward first assertion, do not use things later

[\w](? => any letter or number followed by at, but not The cat sat on The mat. => Match 3

?

(?
does not contain The or The but is followed by sat or mat => The cat, cat sat ont mat => 3 Notice that The or The here is followed by a space.

? ! Negative forward line assertion, undeserving things placed behind

(T|t)he(? ! \scat) => match The or The without (space)cat => The cat sat on The mat. => match a place because The before The is followed by (space)cat

In addition, there is a more similar format (? 🙂 = = = = = = = = = = = = = = = = = = = = = = = =

But I tried. No? B: It doesn’t make any difference

Creation is not easy, if it is helpful to you, welcome to like, collect and share!