当前位置:网站首页>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'>
边栏推荐
- Force buckle 9 palindromes
- Leetcode 剑指 Offer 59 - II. 队列的最大值
- General operation method of spot Silver
- [solved] how to generate a beautiful static document description page
- Idea sets the default line break for global newly created files
- [the most complete in the whole network] |mysql explain full interpretation
- Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
- 【详细】快速实现对象映射的几种方式
- Tensorflow customize the whole training process
- How to get the PHP version- How to get the PHP Version?
猜你喜欢
Condition and AQS principle
TrueType字体文件提取关键信息
Docker compose configures MySQL and realizes remote connection
Huawei Hrbrid interface and VLAN division based on IP
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
How does the crystal oscillator vibrate?
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
干货!通过软硬件协同设计加速稀疏神经网络
Leetcode skimming questions_ Invert vowels in a string
Unity | two ways to realize facial drive
随机推荐
MCU lightweight system core
False breakthroughs in the trend of London Silver
[flask] official tutorial -part2: Blueprint - view, template, static file
【详细】快速实现对象映射的几种方式
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
Maya hollowed out modeling
[flask] official tutorial -part1: project layout, application settings, definition and database access
Tensorflow customize the whole training process
Leetcode skimming questions_ Invert vowels in a string
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
[detailed] several ways to quickly realize object mapping
Dynamics 365 开发协作最佳实践思考
【全网最全】 |MySQL EXPLAIN 完全解读
ORA-00030
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
2022年PMP项目管理考试敏捷知识点(8)
Leetcode 208. 实现 Trie (前缀树)
Basic operations of database and table ----- set the fields of the table to be automatically added
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
【Flask】响应、session与Message Flashing