Python 正则表达式判断文字是否包含 *.shaoxing.com.cn
可以使用正则表达式来判断文字中是否包含 '*.shaoxing.com.cn',具体方法如下:
import re
# 定义正则表达式
pattern = r'.*.shaoxing.com.cn'
# 用正则表达式匹配文字
text = 'This is a test text containing example.shaoxing.com.cn.'
match = re.match(pattern, text)
# 判断是否匹配成功
if match:
print('The text contains *.shaoxing.com.cn.')
else:
print('The text does not contain *.shaoxing.com.cn.')
上述代码中,首先定义了一个正则表达式pattern,其中:
.*表示匹配任意字符任意次数;\.shaoxing\.com\.cn表示匹配字符串.shaoxing.com.cn,其中\.表示匹配.字符。
然后使用 re.match() 方法用正则表达式匹配指定的文字,如果匹配成功,则说明文字中包含 '*.shaoxing.com.cn'。最后根据匹配结果输出相应的提示信息。
需要注意的是,上述正则表达式只能匹配文字中是否包含 '*.shaoxing.com.cn',如果需要匹配更复杂的模式,可能需要修改正则表达式。
原文地址: https://www.cveoy.top/t/topic/owO8 著作权归作者所有。请勿转载和采集!