Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the minor problems that javascript regular expressions are easy to ignore?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "javascript regular expression is easy to ignore what are the small problems", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "what are the small problems that javascript regular expressions are easy to ignore" this article.

First, the special characters in brackets [] do not need to be escaped, such as [/], [.], [*], [?], [+] can directly match the corresponding characters\. *? +. Here are the test results:

So, / [\ d.] / this regular expression actually matches a numeric character or the character ".", which is equivalent to / [\ d\.] /

Second, the difference between match () and exec ()

The main difference between the two is that the regular expression has the global identifier g set.

If the global identifier g is not set, the result of calling string.match (regexp) is the same as that of calling regexp.exec (string)

However, when the global identifier g is set, string.match (regexp) puts all matches into the result array, and the result of regexp.exec (string) only gives the first successful match.

Instead, use the regexp.lastIndex attribute to record where the next match begins. The tests are as follows:

The above is all the contents of the article "what are the minor problems that javascript regular expressions are easy to ignore?" 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report