How to check if a string contains specific format in python?

639 views Asked by At

For example, in python 3, I want to check if a string contains _{}P_, { } can be any number like _5P_, _10P_? Should I use re?

1

There are 1 answers

0
Sunitha On

Use re.search

import re
if re.search(r'_\d+P_', your_string):
    print ('String contains pattern _[digits]P_')