Regex
import repython
Raw string
r'\s*'python
Special Characters
-
.
-
^, $
-
{m}
-
{m, n},{m, n}?
-
*, *?: {0, INF}
-
+, +?: {1, INF}
-
?, ??: {0, 1}
-
\
-
[], [^]: character set, auto-escape special chars.
-
|
-
(): group, use \number to catch (start from 1)
-
(?#...): comment
-
(?=...): lookahead assertion
-
(?!...): negative lookahead assertion
-
(?<=...): lookbehind assertion
-
(?<!...): negative lookbehind assertion
-
\s: [ \t\n\r\f\v]
-
\S: [ ^ \t\n\r\f\v]
-
\w: [a-zA-Z0-9_]
-
\W: [ ^a-zA-Z0-9_]
API
re.search(pattern, string) -> Match-Obj/None
re.match(pattern, string) -> Match-Obj/None
re.fullmatch(pattern, string) -> Match-Obj/None
re.split(pattern, string, maxsplit=0) -> list
re.findall(pattern, string) -> tuple
re.sub(pattern, repl, string, count=0) -> string
re.escape(string) -> string
prog = re.compile(pattern)
res = prog.match(string)
m.groups()
m.group(i)
m.pos
m.endpospython
Examples
re.findall('\((.*?)\)', 'a(b), c (de), f(g(h))')
re.split('\s*', 'a b c\t d')
python