当前位置:网站首页>Representation and basic application of regular expressions
Representation and basic application of regular expressions
2022-07-24 13:13:00 【No fish in Haikou】
1.[abc]:a、b、c Any character in
2.[^abc]: except a、b、c Any character of
3.[a-z]:a、b、c …、z Any character in
4.[a-zA-Z0-9]:a~ z、A~ Z、0~9 Any character in
5.[a-z&&[^bc]]:a~z In addition to b and c Any character other than , among && Express “ And ” The relationship between
6. •: Any character
7.\d: Any number character , amount to [0-9]
8.\w: Word characters are equivalent to [a-zA-Z0-9_]
9.\s: Blank character 、 amount to [\t\n\x0B\f\r]
10.\D: Non empty numeric character
11.\W: Nonword character
12.\S: Nonwhite space character
13.X?: Express 0 Or 1 individual X
14.X*: Express 0 One or any number of X
16.X{n}: Express n individual X
17.X{n,}: Express n One to any number X( Greater than or equal to n individual X)
18.X{n,m}: Express n A to m individual X
19.\d+: Integers
20.\d+.\d+: decimal
21. Regular expression of cell phone number :
String supported regular expression method 1 :
boolean matches(String regex)
Use the given regular expression to verify the format of the current string , Match returns true
notes : Whether or not a given regular expression adds a boundary match "$" They all do full match verification
// String email = "[email protected].cn"; String email = "[email protected]"; /* email Regular expression of [a-zA-Z0-9_][email protected][a-zA-Z0-9]+(\.[a-zA-Z]+)+ */ String regex = "[a-zA-Z0-9_][email protected][a-zA-Z0-9]+(\\.[a-zA-Z]+)+"; boolean match = email.matches(regex); if(match){ System.out.println(" It's the mailbox "); }else{ System.out.println(" Not a mailbox "); }
String The second method of regular expression supported :
String[] split(String regex)
Split the current string according to the part that satisfies the regular expression , And divide the split part into a String Array form returns
String str = "567abc123def456ghi789"; String[] arr = str.split("[0-9]+"); System.out.println(Arrays.toString(arr));
String supported regular expression method 3 :
String replaceAll(String regex,String str)
Replace the part of the current string that satisfies the regular expression with the given content
String str = "abc123def456ghi789klm"; // Convert digital part to #NUMBER# str = str.replaceAll("[0-9]+","#NUMBER#"); System.out.println(str);
边栏推荐
- regular
- Proxy
- 开山之作造假!Science大曝Nature重磅论文学术不端,恐误导全球16年
- EAS environment structure directory
- C code specification
- Summary of embedded network problems (packet loss of network card, unrecognized network card)
- Analysis of ISP one click download principle in stm32
- The price of domestic flagship mobile phones is nearly 6000, but they can't even beat iphone12. It's clear who users choose
- 【论文阅读】TEMPORAL ENSEMBLING FOR SEMI-SUPERVISED LEARNING
- Speech processing based on MATLAB
猜你喜欢

Constraintlayout learn from 0 to 0.n

EAS approval process related table

Cluster construction based on kubernetes v1.24.0 (III)

Speech processing based on MATLAB

开山之作造假!Science大曝Nature重磅论文学术不端,恐误导全球16年

Voice recognition based on MATLAB
EfficientFormer:轻量化ViT Backbone

浅谈Node Embedding

SSM在线考试系统含文档

Research on data governance quality assurance
随机推荐
Constraintlayout learn from 0 to 0.n
How to mount NFS shares using autofs
Embedded cognitive network card PHY self negotiation
28. Rainwater connection
SSM在线租房售房平台多城市版本
2022.07.15 暑假集训 个人排位赛(十)
Research on data governance quality assurance
Is it safe to open an account on Oriental Fortune online? Is there a threshold for opening an account?
2022.07.21
SSM online examination system including documents
34. Add two numbers
LeadTools 22 kit LeadTools super set
leetcode第 302 场周赛复盘
[datasheet] PHY ksz9031 gigabit network chip interpretation
Localstorage
有好用的免费的redis客户端工具推荐么?
Nearly 65billion pieces of personal information were illegally handled in seven years, and the investigation of didi network security review case was announced
SSM online campus album management platform
3. Realize snake and basic game interface
Deep and shallow copies of objects, extends