9"边界匹配

"""边界匹配"""


"""
边界匹配主要用于匹配字符串的边界或字符串中单词的边界。
"""
import re
# ['12']
print(re.findall(r'^\d+', '12-3\n45-6\n78-9')) # ^ 匹配字符串的开头
# ['12', '45', '78']
print(re.findall(r'^\d+', '12-3\n45-6\n78-9', re.M)) # re.M 多行
# ['12']
print(re.findall(r'\A\d+', '12-3\n45-6\n78-9', re.M)) # \A 匹配字符串开始
# ['3', '6', '9']
print(re.findall(r'\d+$', '12-3\n45-6\n78-9', re.M)) # $ 匹配字符串的末尾。
posted @ 2020-05-29 23:35  udbful  阅读(218)  评论(0编辑  收藏  举报