当前位置:网站首页>Regular matching starts with XXX and ends with XXX
Regular matching starts with XXX and ends with XXX
2022-07-07 09:19:00 【Sledgehammer love programming】
Catalog
One 、 What is regular matching ?
Two 、 Regular matching grammar practice
2、 matching XXX Start 、XXX end 、XXX
Preface
Regular matching is an expression that describes a certain rule , It can greatly improve the efficiency of string extraction and string matching .
One 、 What is regular matching ?
Regular expressions ( English :Regular Expression, Often abbreviated to regex、regexp or RE), Also known as regular expression 、 Regular representation 、 Regular expressions 、 Conventional representation is a concept of Computer Science . Regular expressions are described using a single string 、 Match a string that matches a syntax rule . such as Linux In the system Grep command
Two 、 Regular matching grammar practice
1、 Full string match
Full string matching is a prime regular expression , It is a simple search function , Such as query was,test These English only once .
Regular expressions :was
2、 matching XXX Start 、XXX end 、XXX
In the syntax of regular expressions ^ At the beginning , This indicates that XXX To start with , The following example is matching with sh As the beginning word ~
Regular expressions :^sh
In the syntax of regular expressions $ The end of the , This indicates that XXX To start with , The following example is matching with lls As a closing word ~
Regular expressions :lls$
summary
Today, we briefly introduce the regular matching with XXX Start with XXX The grammar of the end , Later, we will find some highlights to analyze in detail .
Last, last , Put a little regular expression benefit :
Remove the left and right blanks :
str.replace(/(^\s*)|(\s*$)/g, '')
Remove all the blanks :
str.replace(/\s+/g, '')
The password needs to be by 8 Upper capital letters 、 Lowercase letters 、 Numbers and special symbols :
/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!.,@$%^&*-]).{8,}$/
Email Address :
^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$
domain name :[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
InternetURL:[a-zA-z]+://[
^s]* or
^http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$`Phone number :
^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])d{8}$
Phone number (“XXX-XXXXXXX”、”XXXX-XXXXXXXX”、”XXX-XXXXXXX”、”XXX-XXXXXXXX”、”XXXXXXX” and ”XXXXXXXX):
^((d{3,4}-)|d{3.4}-)?d{7,8}$
Domestic phone number
(0511-4405222、021-87888822):d{3}-d{8}|d{4}-d{7}
ID number (15 position 、18 Digit number ):
^d{15}|d{18}$
Short ID number ( Numbers 、 Letter x ending ):
^([0-9]){7,18}(x|X)?$
or^d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$
Is the account number legal ( Beginning of letter , allow 5-16 byte , Allow alphanumeric underscores ):
^[a-zA-Z][a-zA-Z0-9_]{4,15}$
password ( Start with a letter , The length is in 6~18 Between , Can only contain letters 、 Numbers and underscores ):
^[a-zA-Z]w{5,17}$
Strong password ( Must contain a combination of upper and lower case letters and numbers , Special characters cannot be used , The length is in 8-10 Between ):
^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
Date format :
^d{4}-d{1,2}-d{1,2}
One year 12 Months (01~09 and 1~12):
^(0?[1-9]|1[0-2])$
A month 31 God (01~09 and 1~31):
^((0?[1-9])|((1|2)[0-9])|30|31)$
xml file :^([a-zA-Z]+-?)+[a-zA-Z0-9]+\.[x|X][m|M][l|L]$
Regular expression for blank lines :
s*
( Can be used to delete blank lines )HTML Tagged regular expression :
<(S*?)[`^>]*>.*?</>|<.*? />
( The version circulating on the Internet is too bad , This one is only part of it , There's nothing we can do about complex nested tags )Regular expression of first and last whitespace characters :
^s*|s*$
or (^s*)|(s*$
) ( Can be used to delete blank characters at the beginning and end of a line ( Including Spaces 、 tabs 、 Page breaks and so on ), Very useful expressions )tencent QQ Number :
[1-9][0-9]{4,}
( tencent QQ Number from 10000 Start )China Post Code :
[1-9]d{5}(?!d)
( China Post code is 6 Digit number )IP Address :
((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))
边栏推荐
- C language pointer (Part 2)
- Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
- Interface test API case, data and interface separation
- Screen automatically generates database documents
- [chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
- RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
- How to count the number of project code lines
- [chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
- 答案在哪里?action config/Interceptor/class/servlet
- [SVN] what is SVN? How do you use it?
猜你喜欢
Unityshader introduction essentials personal summary -- Basic chapter (I)
MySQL master-slave delay solution
Systick滴答定时器
Locust performance test 4 (custom load Policy)
What are the conditions for applying for NPDP?
串口實驗——簡單數據收發
H3C vxlan configuration
Connecting mobile phone with ADB
【云原生】DevOps(一):DevOps介绍及Code工具使用
十二、排序
随机推荐
Interview question: general layout and wiring principles of high-speed PCB
UnityShader入门精要个人总结--基础篇(一)
Some pit avoidance guidelines for using Huawei ECS
Mysql database transaction learning notes
[chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
C语言指针(上篇)
Sublime Text4 download the view in bower and set the shortcut key
MySql数据库-索引-学习笔记
[SVN] what is SVN? How do you use it?
Serial port experiment - simple data sending and receiving
LeetCode每日一题(2316. Count Unreachable Pairs of Nodes in an Undirected Graph)
Cesium load vector data
PMP certificate preparation experience sharing
Detailed learning notes of JVM memory structure (I)
Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
NVIC interrupt priority management
Run can start normally, and debug doesn't start or report an error, which seems to be stuck
Connecting mobile phone with ADB
How to pass the PMP Exam in a short time?
Full link voltage test of the e-commerce campaign Guide