笔记-正则表达式
1.import re
re.match(pattern, string) # 从字符串开头匹配
re.search(pattern, string) # 搜索整个字符串,返回第一个匹配
re.findall(pattern, string) # 返回所有匹配结果的列表
re.sub(pattern, repl, string) # 替换匹配内容
2.match函数的返回结果可以调用span()去返回开始结束的位置
import re
pattern = "^https://www"
str1= input()
match1= re.match(pattern,str1)
print(match1.span())
3.
import re
new_string = re.sub(pattern, repl, string, count=0, flags=0)
4.| 表达式 | 匹配条件 | 例子 |
| ------- | ------------------------- | --------------------- |
| `#[.]+` | 一个 `#` 后面是一个或多个句点 | `#...`、`#.` |
| `^#.+` | 从**字符串开头**的 `#` 开始,后接任意字符 | `#abc123`(必须以 `#` 开头) |
| `#.+` | 任意位置出现 `#`,后面至少有一个字符 | `abc#test`、`#xyz` |
5.*表示字符出现零次或多次