当前位置:网站首页>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}$
边栏推荐
- Crawl Zhejiang industry and trade news page
- How to use diff and patch to update the source code
- [Galaxy Kirin V10] [server] soft RAID configuration
- Advanced order of function
- shell awk
- Two way process republication + routing policy
- 如果不知道這4種緩存模式,敢說懂緩存嗎?
- Recursion and divide and conquer strategy
- DCL statement of MySQL Foundation
- JMeter correlation technology
猜你喜欢

RHCE day 3

20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse

Rhcsa - day 13

When I forget how to write SQL, I

shell awk

Linked list operation can never change without its roots
![[Galaxy Kirin V10] [desktop] printer](/img/ab/066923f1aa1e8dd8dcc572cb60a25d.jpg)
[Galaxy Kirin V10] [desktop] printer

On binary tree (C language)
如果不知道這4種緩存模式,敢說懂緩存嗎?
![[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing](/img/72/5e725a44a50f152b477a4b2907a2d0.jpg)
[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing
随机推荐
Interview and lecture summary 1
Seven examples to understand the storage rules of shaped data on each bit
Write a program to judge whether the elements contained in a vector < int> container are 9.20: exactly the same as those in a list < int> container.
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
Rhcsa day 9
Performance test method
Crawl Zhejiang industry and trade news page
VI text editor and user rights management, group management and time management
Const's constant member function after the function; Form, characteristics and use of inline function
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
[test theory] test the dimension of professional ability
When I forget how to write SQL, I
Recursion and divide and conquer strategy
RHCE - day one
Recursive method to achieve full permutation (C language)
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
From programmers to large-scale distributed architects, where are you (2)
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
[Galaxy Kirin V10] [server] NUMA Technology
Advanced order of function