当前位置:网站首页>regular expression
regular expression
2022-07-04 10:52:00 【Eric%258436】
** If there is a mistake , Thank you for correcting **
If there is a mistake , Thank you for correcting , Please send a private message to the blogger , There is a red envelope for hard work , Worship “ one-word teacher ”.
Please find the paragraphs you need according to the table of contents
Introduction : This blog is organized for individuals Java Learning notes , If there is a mistake , Thank you for correcting . System learning , Welcome to continue to pay attention , Follow up updates Java The back-end project ,Java Part I don't plan to update the basic knowledge , From JavaWeb Start updating articles .
What is RE(Regular Expression)?
Regular expressions , Also known as regular expression .( English :Regular Expression, In code it is often abbreviated as regex、regexp or RE), It's a concept of computer science . Regular expressions are often used for retrieval 、 Replace those that match a pattern ( The rules ) The text of . Regular expressions are not limited to one language , But there are subtle differences in every language . This article aims at Java Version and python edition
The role of regular expressions
Regular expression is a logical formula for string operation , It is to use some specific characters defined in advance 、 And the combination of these specific characters , Form a " Rule string ”, This “ Rule string " A filter logic used to express strings . Use special syntax to represent character classes 、 Quantity qualifier and positional relationship , Then use these special syntax and ordinary characters to represent a pattern .
Features of regular expressions
flexibility 、 Very logical and functional ;
Complex control of strings can be achieved quickly and in a very simple way
For new contacts , It's more obscure
java The use of regular expressions in
stay Java The regular expression in is string type , The verified content is also String type . adopt string Class matches Method to realize the content matching verification . Such as :“ Verified content ”.matches(“ Regular expressions ”)
Regular expression syntax rules
Regular expression syntax rules :[ Content limitation ]{ Length limit }
Content limitationWhen defining rules that qualify content , If no length limit is specified , Then the default length is 1.
Single character qualification :
[a]: Indicates that the current content must be a letter a
Range character limit :
[a-z0-9]: The content can be a-z Any letter between or 0-9 Any number between , Regardless of priority .
Negation restriction :
[^abc]: The content cannot be a or b or c.Length limit
In regular expressions, pass {} To limit the length of the content .
Fixed length :{ Fixed length value }
Range length :{ Minimum length value , Maximum length value }
[a-z]{5}: Indicates that the content range is lowercase letters a To z And the length must be 5
[a-z][2,8}: Indicates that the content range is lowercase letters a To z And the length is 2 To 8 Between , contain 2 And 8
[a-z][2}: Indicates that the content range is lowercase letters a To z And the minimum length is 2, The maximum length is unlimited
[a-z]{0,2}: Indicates that the content range is lowercase letters a To z And the minimum length is o, Maximum length is 2
Length limit symbol
Length limiting symbol refers to the completion of length limiting through predefined symbols .
?: Zero or one . Equate to {0,1}
+: Once or more . Equate to {1,}
*: Zero or more times . Equate to {0,}
Predefined characters
In regular expressions, some pre-defined characters can be used to express the content restriction . The goal is to simplify the definition of content qualification
\d Matches a numeric character , Equivalent to [o-9].
\D Matches a non-numeric character , Equivalent to [^O-9].
\n Match a line break .
\r Match a carriage return .
\s Matches any whitespace characters , Including Spaces 、 tabs 、 Page breaks and so on .
\S Matches any non-whitespace characters .
\t Match a tab .
\w Match any word character that includes an underline . Equivalent to “[A-Za-z0-9_]”".
\W Match any non word character . Equivalent to “[^A-Za-z0-9_]”.
Combination definition of regular expressions
In regular expressions, multiple content and length constraints can be combined to define .
for example Must start with a letter , The minimum length is 4, Maximum length is 8." [a-z]{1}\\w{ 3,8 }"
Common regular expressions
// mailbox ([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}
// | Express or \\. For any character
// IP Address (25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)
// URL http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?
// Id card number (^\\d{18}$)|(^\\d{15}$
边栏推荐
- [Galaxy Kirin V10] [server] KVM create Bridge
- Rhcsa day 9
- Regular expression
- XMIND installation
- Student achievement management system (C language)
- Interview and lecture summary 1
- On binary tree (C language)
- Software testing related resources
- Recursive method to achieve full permutation (C language)
- Rhsca day 11 operation
猜你喜欢
[machine] [server] Taishan 200
Static comprehensive experiment ---hcip1
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
OSPF comprehensive experiment
TS type gymnastics: illustrating a complex advanced type
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
[Galaxy Kirin V10] [server] NUMA Technology
Send a request using paste raw text
[Galaxy Kirin V10] [desktop] FTP common scene setup
Canoe - the third simulation project - bus simulation - 3-2 project implementation
随机推荐
Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)
Two way process republication + routing policy
Student achievement management system (C language)
Canoe-the second simulation project-xvehicle-1 bus database design (idea)
Canoe: the difference between environment variables and system variables
Send a request using paste raw text
Rhcsa12
If you don't know these four caching modes, dare you say you understand caching?
[Galaxy Kirin V10] [server] system startup failed
Strings and characters
Write a program to define an array with 10 int elements, and take its position in the array as the initial value of each element.
[Galaxy Kirin V10] [server] system partition expansion
Postman interface test
Time complexity and space complexity
[test theory] test process management
RHCE - day one
Get the data of the top 100 headlines today with Tianxing data
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
First article
Collection of practical string functions