Home  >  Article  >  Web Front-end  >  In-depth understanding of the analysis of REGEXP object attributes of JS regular expressions

In-depth understanding of the analysis of REGEXP object attributes of JS regular expressions

不言
不言Original
2018-07-11 09:52:111678browse

This article mainly introduces the analysis of REGEXP object attributes for in-depth understanding of JS regular expressions. It has a certain reference value. Now I share it with you. Friends in need can refer to it

Object attributes

Commonly used object attributes mainly include the following:

1.global: Whether to search in full text, the default is false

2.ignore case: Whether to be case sensitive, the default is false

3.multiline: multi-line search, the default value is false

4.lastIndex: It is the last character of the matching content of the current expression, used to specify the starting point of the next match Starting position

5.source: Text string of regular expression

You can access this property directly in the reg object:

let reg1 = /\w/

let reg2 = /\w/gim  // 设置reg属性

reg1.global         // false
reg1.ignoreCase     // false
reg1.multiline      // false
reg1.source         // "\w"

reg2.global         // true
reg2.ignoreCase     // true
reg2.multiline      // true
reg2.source         // "\w"

It is worth mentioning that, These attributes are read-only, and you cannot directly modify their values:

reg1.global         // false

reg1.global = true

reg1.global         // false

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

In-depth understanding of the analysis of grouping of JS regular expressions

In-depth understanding of the analysis of JS regular expressions Analysis of greedy mode and non-greedy mode

The above is the detailed content of In-depth understanding of the analysis of REGEXP object attributes of JS regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn