当前位置:网站首页>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'>
边栏推荐
- C web page open WinForm exe
- 500 lines of code to understand the principle of mecached cache client driver
- DOM introduction
- 【Flask】响应、session与Message Flashing
- Threedposetracker project resolution
- 国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
- MCU lightweight system core
- Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
- National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
- Redis守护进程无法停止解决方案
猜你喜欢

Open source | Ctrip ticket BDD UI testing framework flybirds

3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)

Maya hollowed out modeling

Leetcode skimming questions_ Invert vowels in a string

晶振是如何起振的?

TrueType字体文件提取关键信息

Docker compose configures MySQL and realizes remote connection

DOM introduction

Leetcode skimming questions_ Sum of squares

MATLB|实时机会约束决策及其在电力系统中的应用
随机推荐
selenium 元素定位(2)
Leetcode sword finger offer 59 - ii Maximum value of queue
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
Leetcode 208. 实现 Trie (前缀树)
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
PHP error what is an error?
Code review concerns
网易智企逆势进场,游戏工业化有了新可能
Yii console method call, Yii console scheduled task
SPIR-V初窥
ClickOnce does not support request execution level 'requireAdministrator'
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
NiO related knowledge (II)
伦敦银走势中的假突破
[solved] how to generate a beautiful static document description page
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
MCU lightweight system core
【全网最全】 |MySQL EXPLAIN 完全解读