In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what are the new features of regular expressions in ES2015, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
New features for ES2015 regular expressions:
Based on the original regular expression, ES2015 enhances the support for four-byte unicode characters.
More regular expressions can be found in the regular expressions tutorial section.
I. the use of the RegExp constructor:
Before ES2015, there were two ways to create regular expression objects using the RegExp constructor:
Creation method 1:
Var reg = new RegExp ("antzone", "g")
The first argument to the constructor is the body of the regular expression string, and the second argument is the regular expression modifier.
The above code is equivalent to the following code:
Var regex = / antzone/g
Creation method 2:
Var reg = new RegExp (/ antzone/g)
If the parameter is not a regular expression string, there can be only one parameter; the following is incorrect:
Var reg = new RegExp (/ antzone/,g)
Setting regular expression modifiers with the second parameter is not allowed.
ES2015 changes this behavior so that even if the first parameter is a regular expression object, you can specify the second parameter:
Var reg = new RegExp (/ antzone/gi, "g")
The regular expression modifier specified in the second parameter overrides the modifier in the first parameter.
two。 Regular method of string:
The match (), replace (), search (), and split () methods associated with regular expressions are string objects.
ES2015 has changed this so that when these four methods are called, the instance method of the RegExp object is actually called internally.
(1) .String.prototype.match calls RegExp.prototype [Symbol.match].
(2). String.prototype.replace calls RegExp.prototype [Symbol.replace]
(3). String.prototype.search calls RegExp.prototype [Symbol.search]
(3). String.prototype.split calls RegExp.prototype [Symbol.split]
You can refer to the ES2015 Symbol section about Symbol.
three。 Follow-up assertion (ES2016):
Later line assertions can be found in the regular expression zero width assertion section.
four。 New modifier:
Modifier description u modifier this modifier identifies the correct handling of Unicode characters greater than\ uFFFF. The y modifier states that the match can only start at the position specified in the lastIndex attribute, and the failure of the match will not try the following characters.
five。 New attributes:
Property description the sticky property returns a Boolean value that identifies whether the y modifier is set. The flags property returns the modifier of the regular expression.
six。 New method:
Method description RegExp.escape () (ES2016)
These are all the contents of the article "what are the new features of regular expressions in ES2015?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.