当前位置:网站首页>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}$
边栏推荐
- I What is security testing
- Article publishing experiment
- Huge number (C language)
- DDL language of MySQL database: create, modify alter, delete drop of databases and tables
- Design and common methods of test case documents
- Const's constant member function after the function; Form, characteristics and use of inline function
- Rhcsa learning practice
- /*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/
- Get the data of the top 100 headlines today with Tianxing data
- [Galaxy Kirin V10] [server] system startup failed
猜你喜欢

BGP advanced experiment

Collection of practical string functions

Canoe - the second simulation project -xvihicle1 bus database design (operation)

Performance test method
If you don't know these four caching modes, dare you say you understand caching?

RHCE - day one
![[Galaxy Kirin V10] [desktop and server] FRP intranet penetration](/img/54/7d1b8b7b8226e2820635dd04b92d1c.jpg)
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration

Knapsack problem and 0-1 knapsack problem
![[Galaxy Kirin V10] [server] iSCSI deployment](/img/60/13f43dc584c0768965d60811768948.jpg)
[Galaxy Kirin V10] [server] iSCSI deployment

C language structure to realize simple address book
随机推荐
[Galaxy Kirin V10] [server] system partition expansion
Article publishing experiment
Rhcsa operation
[Galaxy Kirin V10] [server] grub default password
Pod management
VLAN part of switching technology
Canoe-the second simulation project-xvehicle-1 bus database design (idea)
Static comprehensive experiment ---hcip1
Canoe: the difference between environment variables and system variables
Hidden C2 tunnel -- use of icmpsh of ICMP
DDL statement of MySQL Foundation
shell awk
Fundamentals of database operation
Rhcsa day 9
/*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
Appscan installation steps
TS type gymnastics: illustrating a complex advanced type
[Galaxy Kirin V10] [server] NUMA Technology
RHCE day 3
Canoe - the third simulation project - bus simulation - 3-1 project implementation