9.1 匹配單個字元
import re
"""lst = re.findall(正規表示式,字串)"""
# \d 匹配數字
strvar = 'sgdsd5678'
lst = re.findall('\d', strvar)
print(lst)
# \D 匹配非數字
strvar = 'YTWDSD9879_&'
lst = re.findall("\D", strvar)
print(lst)
# \w 匹配字母或數字下劃線(正則函式中,支援中文的匹配)
stravr = "sysh_344@!"
lst = re.findall("\w", stravr)
print(lst)
# \s 匹配任意的空白符("" \t \n \r)
stravr = " \r \t"
lst = re.findall("\s", stravr)
print(lst)
# \S 匹配任意非空白符
stravr = " \r 123 *()"
lst = re.findall("\S", stravr)
print(lst)
# \n 匹配一個換行符
strvar = """"
我愛 學習
"""
lst = re.findall(r"\n", strvar)
print(lst)
# \t 匹配一個製表符
lst = re.findall(r"\t", strvar)
print(lst)