当前位置:网站首页>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'>
边栏推荐
- Accelerating spark data access with alluxio in kubernetes
- 1. Introduction to basic functions of power query
- [network attack and defense training exercises]
- 国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
- selenium 等待方式
- 干货!通过软硬件协同设计加速稀疏神经网络
- [solved] how to generate a beautiful static document description page
- Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
- 【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
- PHP error what is an error?
猜你喜欢

ORA-00030

Open source | Ctrip ticket BDD UI testing framework flybirds

一图看懂!为什么学校教了你Coding但还是不会的原因...

About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)

DOM introduction

C web page open WinForm exe

How to upgrade kubernetes in place

电气数据|IEEE118(含风能太阳能)

Docker compose配置MySQL并实现远程连接

Basic process and testing idea of interface automation
随机推荐
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
Huawei Hrbrid interface and VLAN division based on IP
Yii console method call, Yii console scheduled task
Basic operations of databases and tables ----- unique constraints
Superfluid_ HQ hacked analysis
[技术发展-28]:信息通信网大全、新的技术形态、信息通信行业高质量发展概览
Redis-Key的操作
Maya hollowed out modeling
【Flask】静态文件与模板渲染
selenium 元素定位(2)
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
LeetCode 322. Change exchange (dynamic planning)
[flask] response, session and message flashing
安装Redis
[flask] static file and template rendering
[solved] how to generate a beautiful static document description page
[le plus complet du réseau] | interprétation complète de MySQL explicite
一图看懂!为什么学校教了你Coding但还是不会的原因...
C web page open WinForm exe
【网络攻防实训习题】