当前位置:网站首页>[regular expression] matches multiple characters
[regular expression] matches multiple characters
2022-07-27 15:47:00 【Grapefruit tree CC】
1. Match multiple characters
| Code | function |
|---|---|
| * | Match previous character appears 0 Times or infinite times , You can have it or not |
| + | Match previous character appears 1 Times or infinite times , At least 1 Time |
| ? | Match previous character appears 1 Time or 0 Time , That is to say, there is either 1 Time , Or not |
| {m} | Match previous character appears m Time |
| {m,n} | Match previous character appears from m To n Time |
Example 1:*
demand : Match a string, the first letter is the size character , It's followed by lowercase letters and these lowercase letters can Yes, No
import re
ret = re.match("[A-Z][a-z]*","M")
print(ret.group())
ret = re.match("[A-Z][a-z]*","MnnM")
print(ret.group())
ret = re.match("[A-Z][a-z]*","Aabcdef")
print(ret.group())
Running results :
M
Mnn
Aabcdef
Example 2:+
demand : Match a string , The first character is t, The last string is o, At least one character in the middle
import re
match_obj = re.match("t.+o", "two")
if match_obj:
print(match_obj.group())
else:
print(" Matching failure ")
Running results :
two
Example 3:?
demand : Match such data , however https This s There may be , It could be http This s No,
import re
match_obj = re.match("https?", "http")
if match_obj:
print(match_obj.group())
else:
print(" Matching failure ")
Running results :
https
Example 4:{m}、{m,n}
demand : Match out ,8 To 20 Bit code , It can be in upper and lower case 、 Numbers 、 Underline
import re
ret = re.match("[a-zA-Z0-9_]{6}","12a3g45678")
print(ret.group())
ret = re.match("[a-zA-Z0-9_]{8,20}","1ad12f23s34455ff66")
print(ret.group())
Running results :
12a3g4
1ad12f23s34455ff66
边栏推荐
- [TensorBoard] OSError: [Errno 22] Invalid argument处理
- 使用双星号代替Math.pow()
- 【云享读书会第13期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
- Use deconstruction to exchange the values of two variables
- Interview focus - TCP protocol of transport layer
- Half find
- STL value string learning
- Talk about ThreadLocal
- [正则表达式] 匹配分组
- Jump to the specified position when video continues playing
猜你喜欢

Spark TroubleShooting整理

Spark 3.0 DPP实现逻辑

Summer Challenge harmonyos realizes a hand-painted board

Three uses of static keyword

【剑指offer】面试题49:丑数

QT (five) meta object properties

Interview focus - TCP protocol of transport layer

C language: function stack frame

Causes and solutions of deadlock in threads

使用Lombok导致打印的tostring中缺少父类的属性
随机推荐
数组名是首元素地址吗?
[正则表达式] 匹配多个字符
面试重点——传输层的TCP协议
表格插入行内公式后,单元格失去焦点
Explanation of various attributes of "router link"
C language: data storage
Implementation of spark lazy list files
【剑指offer】面试题53-Ⅰ:在排序数组中查找数字1 —— 二分查找的三个模版
Causes and solutions of deadlock in threads
【剑指offer】面试题51:数组中的逆序对——归并排序
go语言慢速入门——基本内置类型
Spark动态资源分配的资源释放过程及BlockManager清理过程
go语言慢速入门——包
Implement custom spark optimization rules
CAS比较交换的知识、ABA问题、锁升级的流程
/dev/loop1占用100%问题
使用解构交换两个变量的值
Spark Bucket Table Join
Talk about the index of interview questions
Spark RPC