当前位置:网站首页>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}$
边栏推荐
- Aike AI frontier promotion (2.14)
- /*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*/
- How to use diff and patch to update the source code
- [Galaxy Kirin V10] [server] failed to start the network
- Capl: timer event
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- TS type gymnastics: illustrating a complex advanced type
- Application and Optimization Practice of redis in vivo push platform
- Locust installation
- DML statement of MySQL Foundation
猜你喜欢
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
Canoe - the second simulation project -xvihicle1 bus database design (operation)
Collection of practical string functions
Deepmind proposed a Zuan AI, which specially outputs network attack language
RHCE - day one
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Dichotomy search (C language)
183 sets of free resume templates to help everyone find a good job
RHCE day 3
Time complexity and space complexity
随机推荐
IPv6 comprehensive experiment
Safety testing aspects
[Galaxy Kirin V10] [server] NUMA Technology
VI text editor and user rights management, group management and time management
For and while loops
DDL statement of MySQL Foundation
The last month before a game goes online
Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)
Article publishing experiment
Software testing related resources
Using Lua to realize 99 multiplication table
Introduction to tree and binary tree
BGP ---- border gateway routing protocol ----- basic experiment
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
Application and Optimization Practice of redis in vivo push platform
Canoe - the third simulation project - bus simulation - 3-1 project implementation
The most ideal automated testing model, how to achieve layering of automated testing
Jianzhi offer 04 (implemented in C language)
Performance features focus & JMeter & LoadRunner advantages and disadvantages
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)