To remember Python regex easily, we organise Python regex notes from concrete to abstract, and from simple to sophisticate D.
I, Important character:
1, quantitive character:
? : [0,1], *:[0,INFI), +:(0,infi), {N}:[n rep], {m,}:[m, infi), {, n}:[0,n], {m,n}:[m,n],
? (nogreedy option)
2, Begin and End:
^: Beginning, $: ending
3, Making own character class:
[ABC], [^ABC]: ^ Rep non
4, Character classes:
\d,\d,\s,\s,\w,\w
5:dot (or wildcard) character:
. , .*, (.*) ? : Rep Nongreedy Fashion
II, usefull regex arguments
1, Re. Dotall:match all characters, including the newline character.
2, Re. I (re. IGNORECASE): Ignore uppercase
3, Re. Verbose:spread the regex over multiple lines with comments.
4, | : We could use pipe character to cobine all three above arguments.
III, generate Regex procedure:
1, regex = Re.compile (r "")
2.1.1, Regex.search ("")
2.1.2, Regex.search (""). Group (), (or Regex.search (""). Group (No)), greedy Defalut
2.2, Regex.findall ("")
2.3 Regex.sub ("")
3, Re.compile (r "" (
) ", Re. VERBOSE): To manage more complex regrexes.
6:re. Dotall, Re. I
Python regex note