当前位置:网站首页>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'>
边栏推荐
- dried food! Accelerating sparse neural network through hardware and software co design
- 国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
- Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
- [flask] static file and template rendering
- 【Flask】响应、session与Message Flashing
- Leetcode skimming questions_ Verify palindrome string II
- Leetcode skimming questions_ Invert vowels in a string
- 2022年PMP项目管理考试敏捷知识点(8)
- 黄金价格走势k线图如何看?
- How to get all sequences in Oracle database- How can I get all sequences in an Oracle database?
猜你喜欢
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
TrueType字体文件提取关键信息
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
伦敦银走势中的假突破
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
2 power view
Unity | two ways to realize facial drive
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
Cookie concept, basic use, principle, details and Chinese transmission
Mathematical modeling learning from scratch (2): Tools
随机推荐
WGet: command line download tool
module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
伦敦银走势中的假突破
SPIR-V初窺
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
Basic operations of database and table ----- delete data table
3D model format summary
PHP error what is an error?
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
Loop structure of program (for loop)
Code review concerns
[the most complete in the whole network] |mysql explain full interpretation
Maya hollowed out modeling
[技术发展-28]:信息通信网大全、新的技术形态、信息通信行业高质量发展概览
[flask] official tutorial -part2: Blueprint - view, template, static file
【全網最全】 |MySQL EXPLAIN 完全解讀
Internship: unfamiliar annotations involved in the project code and their functions
c#网页打开winform exe
Mongodb problem set