In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use regular expressions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Regular expression, also known as regular representation, conventional representation. (English: Regular Expression, often abbreviated as regex, regexp or RE in code), a concept in computer science. Regular expressions use a single string to describe and match a series that conforms to a syntactic rule. In many text editors, regular expressions are often used to retrieve and replace text that matches a certain pattern.
One: basic matching character:
\ d matching digits eg:'5\ d0numbers-> '580'
\ W matches letters or numbers eg:'\ d\ w\ w-> '8zh'
. Match any character except newline character eg:'zh.'- > 'zh&'
\ s blank character (tab) or space
Second, match the character length:
* represents any character (including 0)
+ indicates at least one character
? Represents 0 or 1 character
{n} represents n characters
{nmenthm} represents nmerm characters.
* * *
One exercise:\ d {3}\ s +\ d {3pr 8}
The answer is here 2333: 3 digits are matched by at least one space or blank character followed by 3 to 8 digits
* * *
>
Third: but if it is simply such a match, it will be a little easier. In the face of complex matching, we also need a more accurate matching method:
[0-9a-zA-Z\ _] can match a number or a letter or an underscore, and test: '0mm,' averse, 'Zero,' _ 'can all match, so the medium expression is a composing way that can or can be matched.
[0-9a-zA-Z\ _] + can match a string consisting of at least one number or letter or underscore
[a-zA-Z\ _] [0-9a-zA-Z\ _] * can match starting with a letter or underscore, followed by any number or letter or underscore
[a-zA-Z\ _] [0-9a-zA-Z\ _] {0jue 19} limit length is 1 to 20, why 1 to 20, and the string immediately after the first bit is limited to 0 to 19, so the maximum length is limited to 20.
A | B can match An or B. [J | j] aina can match jaina or Jaina
^ indicates that it must start with a character, and eg: ^\ d means that it must start with a number.
$means it must end with a character, eg:\ d $means it must end with a number, notice that their expressions ^ are placed in front of the character, and $are placed after the character
Fourth, the verification method in js:
Var reg='\ d {3}\ s +\ d {3jin8}'; var tel='010 123456 console.log (reg.test (tel)); / / true Thank you for reading! This is the end of this article on "how to use regular expressions". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.