- re表达式
表达式 | 备注 |
---|---|
re.search(pattern,string) | 从全部字符串中检索 |
re.match(pattern,string) | 从字符串开头检索 |
re.findall(pattern,string) | 查找所有满足条件的子字符串,返回列表 |
re.sub(“x”,“y”,text) | 把text中的满足正则“x”的字符替换为"y" |
- 正则表达式中符号的含义:
符号 | 含义 |
---|---|
. | 任意多个 |
* | 0次或多次 |
+ | 1次或多次 |
? | 0次或1次 |
\s | 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v] |
- 字符串的判断
str.isalnum() 所有字符都是数字或者字母
str.isalpha() 所有字符都是字母
str.isdigit() 所有字符都是数字
str.islower() 所有字符都是小写
str.isupper() 所有字符都是大写
str.istitle() 所有单词都是首字母大写,像标题
str.isspace() 所有字符都是空白字符、\t、\n、\r