当前位置:网站首页>Learn regular expressions (regexp)
Learn regular expressions (regexp)
2022-07-28 04:13:00 【Big eyes (◉ ɷ ◉) cute】
Regular expressions (RegExp)
summary : Regular expression is a String matching weapon , Can help us search 、 obtain 、 Substitute string
Regular expressions are mainly composed of two parts : Pattern (patterns) And modifiers (flags)
| Method | The descriptor |
|---|---|
| exec | One that performs a search match in a string RegExp Method , It returns an array ( If no match is found, return null). |
| test | A test in a string to see if it matches RegExp Method , It returns true or false. |
| match | One that performs a search match in a string String Method , It returns an array , When there is no match, it will return null. |
| matchAll | A string that performs a search for all matches String Method , It returns an iterator (iterator). |
| search | A match is tested in a string String Method , It returns the matching location index , Or return on failure -1. |
| replace | One that performs a search match in a string String Method , And replace the matching substring with the replacement string . |
| split | A regular expression or a fixed string to separate a string , And store the separated substrings in the array Of String Method |
Modifier flag
| flag | meaning |
|---|---|
| g | All of the , All must match |
| i | Ignore case |
| m | Multi-line matching |
The rules - Character class
| character | meaning |
|---|---|
| \d (digit) | Numbers : from 0 To 9 The characters of |
| \s (space) | The space symbol |
| \w (word) | “ a word ” character , Underline Latin letters or numbers |
| . ( spot ) | It is associated with " Any character other than a newline character " matching |
Reverse class :
- \D The digital : except \d Any character other than , For example, letters .
- \S Non space symbol : except \s Any character other than , For example, letters .
- \W Not a single character : except \w Any character other than , For example, non Latin letters or spaces .
The rules - Anchor point
Symbol ^ And symbols $ It has special meaning in regular expressions , They are called “ Anchor point ”
- Symbol ^ Match the beginning of the text ;
- Symbol $ Match the end of the text ;
Word boundaries : \b ( The next position corresponds to \b)

The rules - Escape string
Use special characters as regular characters , Just put a backslash in front of it ;
for example :[] \ ^ $ . | ? * + ( )
aggregate (Sets) And scope (Ranges)
Sometimes we just need to select one of multiple matching characters :
- Square brackets […] A few characters or character classes in mean “ Search for any one of the given characters ”;
aggregate (Sets)
for instance ,[eao] It means finding in 3 Characters ‘a’、‘e’ perhaps `‘o’ Any one of ;
Range (Ranges)
- Square brackets can also contain character ranges ;
- for instance ,[a-z] Will match from a To z Letters in the range ,[0-5] From 0 To 5 The number of ;
- [0-9A-F] Represents two ranges : It searches for a character , Number satisfied 0 To 9 Or letters A To F;
- \d —— and [0-9] identical ; \w —— and [a-zA-Z0-9_] identical ;
quantifiers (Quantifiers)
The words used to describe the quantity we need are called quantifiers ( Quantifiers ).
Number {n}
- The exact number of digits :{5}
- The number of digits in a certain range :{3,5}
abbreviation :
- +: representative “ One or more ”, amount to {1,}
- ?: representative “ Zero or one ”, amount to {0,1}. let me put it another way , It makes symbols optional ;
- *: Represents the “ Zero or more ”, amount to {0,}. in other words , This character can appear or not appear many times ;
greedy (Greedy) And inertia (lazy) Pattern
Greedy mode : By default, the matching rule is to find the matching content , Will continue to look back , Always find the last matching content
Lazy mode : The quantifier in lazy mode is the opposite of that in greedy mode . As long as the corresponding content is obtained , No more backward matching .
More regular queries : https://c.runoob.com/front-end/854/
2022.0713
边栏推荐
- Fedformer MOE module
- Leetcode 0140. word splitting II
- Filters, interceptors, listeners
- [reach out to Party welfare] the easiest way to scan the H5 page in wechat
- 2022.7.13-----leetcode.735
- [MySQL database] index and transaction (often used in interview)
- Monotonic stack - 739. Daily temperature
- C language: find the number of 1 in binary stored in memory as an integer
- Servlet usage
- Move notice!
猜你喜欢

From Clickhouse to Snowflake: MPP query layer

Null security and exception

Detailed explanation of string + memory function (C language)

Servlet usage

jdbc使用

Cyber Nuwa, how to make digital people?

null安全与异常

pl/sql之各参数详解(“箱子模型“)

RT thread changes the print serial port (add other functions on the basis of BSP)

Leetcode58. Length of the last word
随机推荐
Kingbasees Security Guide for Jincang database -- 5.2. data integrity protection
Day08 redis的基础知识
Super easy to use PC end long screenshot tool
C # cross thread refresh foreground UI
Kingbasees security guide of Jincang database -- 6.2. Configuration files related to authentication
numeric_ Limits the range and related attributes of each data type learned
"Three no's and five requirements" principle of enterprise Digitalization Construction
[Luogu p4590] garden party (DP set DP)
A little advice for students - how to build their own knowledge system?
VAE generation model (with VAE implementation MNIST code)
Leetcode 0140. word splitting II
[MySQL database] index and transaction (often used in interview)
Power consumption: leakage power
Kingbasees Security Guide for Jincang database -- 4 data access protection
功耗:Leakage Power
月薪28K学员 自动化测试经验分享
Convert py file to exe executable file
@Requiredargsconstructor annotation
Classification cluster analysis
【无标题】