@websec007
2020-07-30T03:20:26.000000Z
字数 753
阅读 1279
python编程快速上手
以下是一个文本字符串,我们需要将其中的号码匹配检索出来;
"Aliec Phone Number: 123-123-1234"
import re
regex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
# 需要被匹配检索的字符串对象:strings = "Aliec Phone Number: 123-123-1234"# 使用正则表达式去匹配检索电话号码字符串信息match = regex.search(strings)
string_match = match.group()print("Phone-Num >>> {}".format(match_strings))
# 导入re默认模块import re# 以下是一个文本字符串,我们需要将其中的号码匹配检索出来;strings = "Aliec Phone Number: 123-123-1234"#(1)创建一个规则表达式对象(regular expression: regex)regex = re.compile(r'\d\d\d-\d\d\d\-\d\d\d\d')#(2)使用规则表示对象去匹配检索字符串对象match = regex.search(strings)#(3)打印匹配检索结果信息match_strings = match.group()print("Phone-Num >>> {}".format(match_strings))
