In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "JavaScript regular expression case analysis", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "JavaScript regular expression case analysis"!
1. Overview
In JavaScript, you can use / / to create a regular expression object, or you can use new RegExp ()
The commonly used methods related to regularity are match, test, and replace.
Where match,replace is a method on a string and test is a method on a regular object.
Let's look at the specific illustration:
two。 Match single character
/ reg/ can directly match the specific string reg.
The brackets [] in / [arzy] / represent any single character in the matching arzy.
Middle bar in / [fmurh] /-represents any single character from f to h in the matching alphabetical order
/ [1-3] / represents the matching numbers 1 to 3
3. Regular option
Regular objects can also be followed by options. Common options in JavaScript are:
I-ignores case
M-represents multi-line matching
G-represents a global match (can be matched multiple times)
4. Boundary matching
^-represents the beginning of the matching string
$- represents the end of the matching string
5. Character matching
. -can match any character except a newline character
\ d-can match any number
\ d-can match any non-number
\ s-matches any white space character
\ s-matches any non-white space character
\ n-match line feeds
\ w-it is actually equivalent to [A-Za-z0-9 _], that is, matching alphanumeric underscores
6. Quantifier matching
*-match 0 or more times
+-match one or more times
?-match 0 or 1 time
{3}-match 3 times
{2pr 4}-match 2, 3, or 4 times
{2,}-match 2 or more times
7. Grouping
Parentheses represent grouping in the rule and are 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 the pipe symbol in parentheses |, it represents or
8. Special character
You need to add a backslash when matching special symbols.
The special characters in JS are ^ $\. * +? () [] {} |
So if you need to match the asterisk *, you need to write:
\ *
9. Take mismatch
To match any character except a character, you need to use ^ in square brackets []
So far ^ has two meanings:
If used at the beginning of a regular expression, it represents the beginning of a matching string
If used inside the bracket [], it means to match a character other than this character.
Thank you for your reading, the above is the content of "JavaScript regular expression example analysis", after the study of this article, I believe you have a deeper understanding of the problem of JavaScript regular expression example analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.