String 如何在python中检查字符串是否包含特定格式?

String 如何在python中检查字符串是否包含特定格式?,string,python-3.x,format,include,contain,String,Python 3.x,Format,Include,Contain,例如,在Python3中,我想检查字符串是否包含{}p{/code>,{}可以是任何数字,如\u5p{/code>,\u10p{/code>?我应该使用re吗?使用re.search import re if re.search(r'_\d+P_', your_string): print ('String contains pattern _[digits]P_') 导入re;重新匹配(“\ud+P”、“\u10p”)

例如,在Python3中,我想检查字符串是否包含
{}p{/code>,{}可以是任何数字,如
\u5p{/code>,
\u10p{/code>?我应该使用re吗?

使用
re.search

import re
if re.search(r'_\d+P_', your_string):
    print ('String contains pattern _[digits]P_')
导入re;重新匹配(“\ud+P”、“\u10p”)