Regular expressions;
Import re import module
python retrieves whether there is a character string "python"
a.index ( 'python')> -1 Returns true false
'Python' in A Returns true false
Using regular expressions;
Re Import
A = "Python | C ++ | cudfdhf"
R & lt = the re.findall ( "Python", A)
can not retrieve return empty
Meta characters: '\ d' represents 0-9 '\ D' represents a non-digital
re.findall ( "\ d", a ) all the numbers to find a
Character set
a [cf] d represents acd AFD or
a bunch [cf] d represents
a [cf] d ^ represents the second character is not cf
a [] represents a set of characters or relationship
Summarizes character set
[0-9]
[0-9] ^
\ s set of blank characters (including spaces newline tab)
Quantifier
the re.findall ( '[az] {3,6}', a) // aa2 ssssf3 matches found out ssssf 3-6 consecutive letters based on greedy
the re.findall ( '[az] {3,6}?' , a) // aa2 ssssf3 matches found out ssssf 3-6 non-consecutive letters based greedy
* Match 0 or countless times
+ Match 1 or many times
? Match zero or 1
Border matching
^ on the match from the first character of
$ characters from the last match
Matching set
r = re.findall ( '(python' {3}, a) 3 looking group python