“This is the sixth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

1. Prepare knowledge

  1. Escape character (\n,\f,\r,\t,\v)
  2. Multiline string
// Multi-line strings make use of escape characters
var string = 'i am \
liyilin\
';
Copy the code

2. Create regular expressions

  1. literal
  2. new RegExp(“”, “igm”)

The regular expression defaults to greedy matching. If you don’t want greed to match, right?

3. The attribute

  1. I: Ignore case
  2. G: Global matching
  3. M: Multi-line matching

4. The expression

  1. [0-9]
  2. [a-z]
  3. [A-Z]
  4. [A-z]
  5. ^ : Put in the expression to represent not
  6. (\w)
Var reg = /(\w)\1/g; Var STR = 'aabbccdd'; str.match(reg) -- > ['aa', 'bb', 'cc', 'dd']Copy the code
  1. .=== [\r\n]

“| | BCD (ABC) a pipeline of Linux

5. Yuan character

  1. \w === [0-9A-z_]
  2. \W === [^\w]
  3. \d === [0-9]
  4. \D === [^\d]
  5. \s === whitespace character
  6. \S === [^\s]
  7. \ B: Match word boundaries
  8. \B: Match non-word boundaries

6. Quantifiers

  1. n+
  2. n*
  3. n? : n Occurs 0-1 times
  4. n{x}
  5. n{x,y}
  6. n{x,}
  7. ^n
  8. n$

7. Forward pre-check (assertion)

  1. ? = expression
  2. ? ! expression

This expression does not participate in selection, only in constraints

Method 8.

  1. RegExp
    1. Reg.test (STR): Returns true if STR matches successfully
    2. reg.exec(str)
        // If reg is a global match, exec performs like a seamless switch,
        // The cursor is lastIndex
        // If there is a subexpression in the reg, the value of the subexpression is returned for each match
        var reg = /(\w)\1(\w)\2/g;
    	var str = 'aabbccdd';
    	console.log(reg.exec(str)); 
    	//["aabb", "a", "b"] -->lastIndex = 4
    	console.log(reg.exec(str)); 
    	//["ccdd", "c", "d"] -->lastIndex = 8
        console.log(reg.exec(str)); 
        //null -->lastIndex = 0
        
        //reg.lastIndex can be changed manually
        reg.lastIndex = 4;
        console.log(reg.exec(str));
    	//["ccdd", "c", "d"] -->lastIndex = 8
    Copy the code
  2. String
    1. str.match(reg)


    Similar to exec, except that if reg is a global match, only all matches are returned, and no subexpression is returned. 2.str.search (erg)

    3. Str.split (reg)

    Return subexpression 4. Str.replace (reg,target)

    This is an outrageously powerful feature

       console.log(str.replace(reg, str));
       // The second $1 is the result of the subexpression 1
       console.log(str.replace(reg, "$1, $2");
       //
       console.log(str.replace(reg, function ($, $1) {
           return $1 + 'abc';
       })
    Copy the code

9.? : Does not capture groups

10. Qualifiers and locators

  1. qualifiers
  2. Localizers: Localizers do not match and cannot be used with qualifiers
    1. ^
    2. $
    3. (\ \ b b),

Past wonderful articles

  • Cow guest latest front-end JS written test 100 questions
  • Grab the latest front end test five hundred data analysis JS interview hot spots
  • Native JavaScript soul torture (2), can you answer all correctly?
  • Native JavaScript soul Test (1), how much can you answer?
  • A thorough understanding of prototypes and prototype chains in JavaScript
  • JavaScript precompilation learning
  • Complete understanding of EventLoop in JavaScript
  • “2W word big chapter 38 interview questions” completely clear JS this pointing to the problem

After the language

Guys, if you find this article helpful, give a like to 👍 or follow ➕ to support me.

In addition, if this article has a question, or do not understand part of the article, you can reply to me in the comment section, we come to discuss, learn together, progress together!

If you feel confused in the comments section, you can also add my wechat or QQ for detailed communication, and the name is battlefield small bag.