1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| re.findall(pattern, name_str)
re.search(pattern, name_str).group()
re.match(pattern, name_str).group()
text = "Hello, world! 123"
result = re.match(r'\d+', text) print(result)
re.split(pattern, string, maxsplit=0, flags=0)
re.sub(pattern, repl, string, count=0, flags=0)
re.subn(pattern, repl, string, count=0, flags=0)
re.compile(pattern, flags=0)
pattern = re.compile(r'\b[\w.-]+@[\w.-]+\.\w+\b')
text = "联系我 at john@example.com 或 SUPPORT@EXAMPLE.COM"
emails = pattern.findall(text) print(emails)
|