Python 正在尝试使用startswith检查字符串
我试图使用startswith检查某个东西是否以符号“开头,这是因为您不使用正则表达式Python 正在尝试使用startswith检查字符串,python,python-3.x,string,re,startswith,Python,Python 3.x,String,Re,Startswith,我试图使用startswith检查某个东西是否以符号“开头,这是因为您不使用正则表达式line.startswith(“的文档的哪一部分使您得出结论,它与正则表达式一起工作?re.match从字符串开头隐式匹配,因此不需要^ import re # Edit as @donkopotamus pointed well that match doesn't require '^' at the begining in_re = re.compile(r'<\w+') print(bool
line.startswith(“的文档的哪一部分使您得出结论,它与正则表达式一起工作?re.match
从字符串开头隐式匹配,因此不需要^
import re
# Edit as @donkopotamus pointed well that match doesn't require '^' at the begining
in_re = re.compile(r'<\w+')
print(bool(in_re.match('<test true')))
print(bool(in_re.match('test false')))
print(bool(in_re.match('test <false 2')))
True
False
False