面试题答案
一键面试在Python的re
模块中,匹配除换行符之外的任意单个字符使用.
符号。
示例代码如下:
import re
pattern = '.'
string = 'a1b@c'
matches = re.findall(pattern, string)
print(matches)
上述代码使用re.findall
函数查找字符串string
中符合模式pattern
(即除换行符外的任意单个字符)的所有子串,并将匹配结果输出。输出结果为:['a', '1', 'b', '@', 'c']
。