当前位置:网站首页>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);
边栏推荐
- 2022.07.21
- EAS environment structure directory
- Embedded cognitive network card PHY self negotiation
- ESP32ADC
- SSM hospital inpatient management system
- How to mount NFS shares using autofs
- Question 10: find numbers in an array with rows and columns in order
- 基于matlab的声音识别
- Atcoder beginer contest 261e / / bitwise thinking + DP
- Copy of array and array address value
猜你喜欢

IUAP spring training data in 2022, Zhongtai training report

Modern data architecture selection: Data fabric, data mesh

The price of domestic flagship mobile phones is nearly 6000, but they can't even beat iphone12. It's clear who users choose

About thread (3) thread synchronization

Speech processing based on MATLAB

指针进阶部分(1)

EAS environment structure directory

Roller_ Block default behavior_ Zero roll event compatible

leetcode第 302 场周赛复盘
This is how the permission system is designed, yyds
随机推荐
CMake基本语法(一)
I 用c I 实现 大顶堆
[datasheet phy] interpretation of ksz8081 data manual
基于matlab的语音处理
SSM在线考试系统含文档
Copy of array and array address value
20201127 use markdown to draw UML diagrams, graphviz installation experience hematemesis finishing
Is it safe to open an account on Oriental Fortune online? Is there a threshold for opening an account?
How to draw Bezier curve and spline curve?
Embedded cognitive network card PHY self negotiation
Arduino框架下ESP32 EEPROM库函数实现对各数据类型保存示例
class
35.8. string conversion integer (ATOI)
English语法_不定代词 - 概述
The MySQL select delay scenario corresponds to that all database query statements will be delayed. After the scenario injection, I executed one
2022.07.15 summer training personal qualifying (10)
About thread (3) thread synchronization
On node embedding
Nearly 65billion pieces of personal information were illegally handled in seven years, and the investigation of didi network security review case was announced
ESP32ADC