1.re.findall ("A", "AB")
A: Match rule ab: what to match
The result is returned as a list: [' a ']
2. Metacharacters: ".", "^", "$", "*", "+", "?", "{}", "[]", "|", "()", "\"
"." : matches any character except the line break "\ n";
Import= Re.findall ('ab.d',"abcdefg" = Re.findall ('ab.e',"abcdefg") Print # [' ABCD '] Print # []
"^": Match string start
Import= Re.findall ('^ab',"abcdefg" = Re.findall ('^bc',"abcdefg") Print#[' AB ']print#[]
' $ ': Match string end
Import= Re.findall ('ab$',"abcdefg" = Re.findall ('fg$',"abcdefg") Print#[]print#[' FG ']
"*": match the previous character 0 or unlimited times
Import= Re.findall ('ab*',"abbdefg" = Re.findall ('ab*',"acdefg") Print#[' ABB ']print#[' a ']
"+": Match the previous character 1 or unlimited times
"?" : matches the previous character 0 or 1 times
' {n} ': matches the previous character N times
' {n,m} ': matches the previous character N to M (closed interval)
"[AB]": Match A or b
ImportReA= Re.findall ('a[bc]d',"ABCDEFG") B= Re.findall ('a[bc]d',"ABDEFG") C= Re.findall ('a[bc]d',"ACDEFG")PrintA#[]PrintB#[' Abd ']PrintC#[' ACD ']
"\": 1. Backslash followed by meta-character, so that metacharacters remove special functions
2. followed by ordinary characters, creating special functions
3. Strings that match the string corresponding to the reference sequence
Regular expressions for Python