当前位置:网站首页>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}$
边栏推荐
- Locust learning record I
- IPv6 comprehensive experiment
- C language structure to realize simple address book
- /*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does
- [untitled]
- Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
- Installation of ES plug-in in Google browser
- Jemeter plug-in technology
- Design and common methods of test case documents
- On binary tree (C language)
猜你喜欢
![[Galaxy Kirin V10] [server] system partition expansion](/img/49/5d3e28eab45d300bd5695e47b35e6b.jpg)
[Galaxy Kirin V10] [server] system partition expansion
If you don't know these four caching modes, dare you say you understand caching?

Time complexity and space complexity
![[Galaxy Kirin V10] [server] FTP introduction and common scenario construction](/img/ef/f0f722aaabdc2d98723cad63d520e0.jpg)
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction

Jemeter script recording

JMeter Foundation

VI text editor and user rights management, group management and time management

Huge number multiplication (C language)

JMeter common configuration components and parameterization

Canoe - description of common database attributes
随机推荐
Rhcsa operation
OSPF comprehensive experiment
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
[Galaxy Kirin V10] [desktop] FTP common scene setup
Rhcsa - day 13
Hidden C2 tunnel -- use of icmpsh of ICMP
For and while loops
Discussion | has large AI become autonomous? Lecun, chief scientist of openai
Software sharing: the best PDF document conversion tool and PDF Suite Enterprise version sharing | with sharing
[Galaxy Kirin V10] [desktop] printer
JMeter assembly point technology and logic controller
RHCE day 3
Using SA token to solve websocket handshake authentication
Performance features focus & JMeter & LoadRunner advantages and disadvantages
C language structure to realize simple address book
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
Evolution from monomer architecture to microservice architecture
Day06 list job
Canoe-the second simulation project-xvehicle-1 bus database design (idea)
Application and Optimization Practice of redis in vivo push platform