当前位置:网站首页>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'>
边栏推荐
- Unreal browser plug-in
- Leetcode 208. Implement trie (prefix tree)
- You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
- 什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
- 剑指 Offer 12. 矩阵中的路径
- Paddle framework: paddlenlp overview [propeller natural language processing development library]
- 竞赛题 2022-6-26
- [flask] static file and template rendering
- Folio. Ink is a free, fast and easy-to-use image sharing tool
- 【详细】快速实现对象映射的几种方式
猜你喜欢

leetcode刷题_验证回文字符串 Ⅱ

Leetcode skimming questions_ Sum of squares

DOM introduction

Yii console method call, Yii console scheduled task

Threedposetracker project resolution

Basic operations of databases and tables ----- unique constraints

NumPy 数组索引 切片

Maya hollowed out modeling

Unity | two ways to realize facial drive

How to see the K-line chart of gold price trend?
随机推荐
Yii console method call, Yii console scheduled task
剑指 Offer 12. 矩阵中的路径
Huawei Hrbrid interface and VLAN division based on IP
National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
How to get all sequences in Oracle database- How can I get all sequences in an Oracle database?
A picture to understand! Why did the school teach you coding but still not
selenium 元素定位(2)
Force buckle 1020 Number of enclaves
What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
Docker compose configures MySQL and realizes remote connection
普通人下场全球贸易,新一轮结构性机会浮出水面
Cookie concept, basic use, principle, details and Chinese transmission
[le plus complet du réseau] | interprétation complète de MySQL explicite
Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
UE4 unreal engine, editor basic application, usage skills (IV)
Basic operations of database and table ----- set the fields of the table to be automatically added
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
MATLB|实时机会约束决策及其在电力系统中的应用