In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you the front-end regular expression example analysis, I believe most people still do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
1. overview
In JavaScript, you can create a regular expression object using//or new RegExp().
Common regular-related methods are match, test, and replace.
where match and replace are methods on strings, and test is a method on regular objects.
2. Match single character
/reg/can match a specific string reg directly.
The square brackets [] in/[arzy]/match any single character in arzy.
Middle bar in/[f-h]/-represents any single character from f to h in the matching alphabetical order
/[1-3]/represents matching numbers 1 to 3
3. regular option
Regular objects can also be followed by options. Common options in JavaScript are:
i -means ignore case
m -stands for multi-row matching
g -stands for global match (can match multiple times)
4. boundary matching
^ -Represents the beginning of a matching string
$ -represents the end of the matching string
5. character matching
.
- Can match any character except newline
\d
- Can match any number
\D
- Can match any
non
digital
\s
- Match any white space character
\S
- matches any
non
white space characters
\n
- matching line
\w
- It's actually equivalent to
[A-Za-z0-9_]
match alphanumeric underscore
6. quantifier matching
*
- Match 0 or more times
+
- Match one or more times
?
- Match 0 or 1 times
{3}
- Match 3 times
{2,4}
- Match 2, 3 or 4 times
{2,}
- Match 2 or more times
7. packet
() Parentheses represent grouping in regular, generally used in match methods to return full matches plus multiple grouping results, if the g option is used, only full matches are returned.
You can use pipe symbols in parentheses| It represents or
8. special characters
backslash is required to match special symbols\
Special characters in JS are ^ $ \ . * + ? () [] {} |
So if you need to match an asterisk *, you need to write:
\*
9. take no match
To match any character except one, use ^in brackets []
So ^has two meanings:
If used at the beginning of a regular expression, represents the beginning of a matching string
If used inside square brackets [], it represents a match other than this character
The above is "front-end regular expression sample analysis" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.