ES2015 regular expressions have new features:
Based on the original regular expression, ES2015 has enhanced the support for four-byte unicode characters and other functions.
For more regular expression content, please refer to the Regular Expression Tutorial section.
1.Usage of RegExp constructor:
Prior to ES2015, there were two ways to create regular expression objects using the RegExp constructor:
Creation method one:
var reg = new RegExp("antzone","g");
The first parameter of the constructor is the regular expression string body, and the second parameter is the regular expression modifier.
The above code is equivalent to the following code:
var regex = /antzone/g;
Creation method two:
var reg = new RegExp(/antzone/g);
If the parameter is not a regular expression string, then there can only be one parameter; the following writing method is wrong:
var reg = new RegExp(/antzone/,g);
Regular expression modifiers are not allowed using the second parameter.
ES2015 changes this behavior, even if the first parameter is a regular expression object, the second parameter can be specified:
var reg = new RegExp(/antzone/gi,"g");
The regular expression modifier specified by the second parameter overrides the modifier in the first parameter.
2. Regular method of strings:
The match(), replace(), search() and split() methods related to regular expressions belong to string objects.
ES2015 has made changes to this. When these four methods are called, the instance method of the RegExp object is actually called internally.
(1). Call [].
(2). Call []
(3). Call []
(3). Call []
For Symbol, please refer to the ES2015 Symbol chapter.
3. Post-line assertion (ES2016):
Refer to the following assertionRegular expression zero width assertionOne chapter.
4. Added modifiers:
Modifier | describe |
u modifier | This modifier identifies Unicode characters larger than \uFFFF. |
y modifier | It is stipulated that the matching can only start from the position specified by the lastIndex attribute, and the subsequent characters will not be tried again if the matching fails. |
5. New attributes:
property | describe |
sticky attribute | Returns a Boolean value to identify whether the y modifier is set. |
flags attribute | Returns a modifier for the regular expression. |
6. New methods:
method | describe |
()(ES2016) |