当前位置:网站首页>Regular expressions: examples (1)
Regular expressions: examples (1)
2022-07-06 01:38:00 【Live up to your youth】
1、 user name
The user name can contain the following characters :
1、26 Upper and lower case English letters are expressed as a-zA-Z.
2、 The number is expressed as 0-9.
3、 The underline is indicated by _.
4、 A dash in the middle indicates -.
The user name consists of several letters 、 Numbers 、 Underline and underline form , So you need to use + Express 1 Appear several times or more . According to the above conditions, the expression of user name can be :
[a-zA-Z0-9-_]+
>>> import re
>>> pattern = r"[a-zA-Z0-9_-]+"
>>> text = "lily123"
>>> match = re.search(pattern, text)
>>> match
<re.Match object; span=(0, 7), match='lily123'>
2、HTML label
matching html Medium <p> label :
<p((\s\S)*)<\/p>
>>> import re
>>> text = '''<p class="odd" id="odd">123</p>'''
>>> pattern = r"<p(([\s\S])*)<\/p>"
>>> re.search(pattern, text)
<re.Match object; span=(0, 31), match='<p class="odd" id="odd">123</p>'>
3、 cell-phone number
The first digit of the mobile phone number is 1, The second digit cannot be 0、1、2, Altogether 11 position . The regular expression obtained from the above conditions is :
^1[^012]\d{9}$
>>> import re
>>> pattern = r"^1[^012]\d{9}$"
>>> phone_number = "13174335288"
>>> match = re.search(pattern, phone_number)
>>> match
<re.Match object; span=(0, 11), match='13174335288'>
边栏推荐
- ClickOnce 不支持请求执行级别“requireAdministrator”
- 【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
- Docker compose配置MySQL并实现远程连接
- PHP error what is an error?
- Format code_ What does formatting code mean
- Mongodb problem set
- Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
- Folio. Ink is a free, fast and easy-to-use image sharing tool
- 【全網最全】 |MySQL EXPLAIN 完全解讀
- 2 power view
猜你喜欢
C web page open WinForm exe
Basic operations of databases and tables ----- non empty constraints
3D model format summary
[detailed] several ways to quickly realize object mapping
【SSRF-01】服务器端请求伪造漏洞原理及利用实例
电气数据|IEEE118(含风能太阳能)
Threedposetracker project resolution
dried food! Accelerating sparse neural network through hardware and software co design
Initialize MySQL database when docker container starts
【已解决】如何生成漂亮的静态文档说明页
随机推荐
c#网页打开winform exe
internship:项目代码所涉及陌生注解及其作用
【网络攻防实训习题】
02.Go语言开发环境配置
Basic operations of database and table ----- set the fields of the table to be automatically added
A glimpse of spir-v
竞赛题 2022-6-26
2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
Open source | Ctrip ticket BDD UI testing framework flybirds
Leetcode skimming questions_ Invert vowels in a string
D22:indeterminate equation (indefinite equation, translation + problem solution)
Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
[flask] official tutorial -part1: project layout, application settings, definition and database access
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
How does Huawei enable debug and how to make an image port
黄金价格走势k线图如何看?
【全网最全】 |MySQL EXPLAIN 完全解读
leetcode刷题_验证回文字符串 Ⅱ
【Flask】静态文件与模板渲染