What is a regular expression?
A regular expression is a small, highly specialized, language that is used primarily for string processing
Regular expressions are a common language, implemented in Python via the RE module, and the import re
Tools: on-line regular expression testing
http://tool.oschina.net/regex/
Http://www.jb51.net/shouce/jquery1.82/regexp.html
Character match-Normal character
Most characters match themselves exactly. The expression shit matches the string "shit" exactly
Character match-Meta character
^ Match beginning of Line
$ Match Line End
* Match the previous character by more than or equal to 0 times
? Matches the previous character 0 or 1 times to indicate whether a
+ Match the previous character by more than or equal to 1 times
. Match single character
[] Specify a character set [ABC]; [A-z]; [1-9]; [A-za-z0-9] (or a relationship, such as [ABC] indicates the presence of a or B or c other similar)
In addition, you can match characters that are not in the interval range [^5], where you must use []
\ transfer metacharacters to normal characters \ \, \^, \[
Eg: want to match the number in the string (ONE1TWO2THREE3FOUR4)
Regular:/d
{} Number of repetitions
What does eg:a{4} mean?
Match AAAA
| Represents or, X|y represents a match for x or Y
() grouping
eg
Regular: C|d, match string "ABCD", result?
Cd
Regular: (AB), match string "ABC ADC ABB", result?
Explanation: AB whole goes to match string
AB AB
Summarize:
Practice:
data [' AD123453 ', ' AC345466 ', ' AR695235 '], matching 2 uppercase letters and 6 digits
\W{2}\D{6} \w+\d+ [A-z]{2}[0-9]{6}
Match the domestic mobile phone number
Features: All numbers
Opening 1X
Length 11
^ (13|15|18) [0-9]{9}
Python Basics-Regular 1