Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-02 03:43:43 10月06日 Update

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!

Tags: Regular expression result character question global content identity identifier article study help test special same success no location function actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux MySQL Apple vpn