In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to use js regular expression to match numbers related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this article on how to use js regular expression to match numbers will have something to gain, let's take a look.
1. Regular expressions use the
The most basic way to use regular expressions to match strings is the exec method of regular objects:
This method returns an array where the first element of the array is the text that matches the regular expression, followed by the text, if any, that matches several sub-expressions of the regular expression. If the match fails, null is returned.
The array returned by the exec method has two properties in addition to length:
Index: represents the position of the first character of the matching text
Input: stores the retrieved string
In addition to using the exec method, we can also use the match method of the String object, which is used similar to exec
Var str= "0hello1"; str.match (/\ dwatches /); / / ["0", index: 0, input: "0hello1", groups: undefined] str.match (/\ dhammer / g); / / ["0", "1"]
two。 Matching number
(1) user name regularization
/ / user name is regular, 4 to 16 digits (letters, numbers, underscores, minus signs) var uPattern = / ^ [a-zA-Z0-9 letters -] {4pm 16} $/; / output trueconsole.log (uPattern.test ("caibaojian"))
(2) password strength regularity
/ / password strength is regular, at least 6 characters, including at least 1 uppercase letter, 1 lowercase letter, 1 number, 1 special character var pPattern = / ^. * (? =. {6,}) (? =. *\ d) (? =. * [Amurz]) (? =. * [Amurz]) (?) (? =. * [! @ # $% ^ & *?]). / / output trueconsole.log ("=" + pPattern.test ("caibaojian#"))
(3) Integer regularity
/ / positive integer regular var posPattern = / ^\ dhammer / negative integer regular var negPattern = / ^ -\ dhammer / integer regular var intPattern = / ^ -?\ dhammer / output trueconsole.log (posPattern.test ("42")); / / output trueconsole.log (negPattern.test ("- 42")); / / output trueconsole.log ("- 42")) This is the end of the article on "how to match numbers with js regular expressions". Thank you for reading! I believe you all have some knowledge of "how to match numbers with js regular expressions". If you want to learn more, you are 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.