re.match returns false even when string pattern match

115 Views Asked by At

I am trying to match a pattern with the string, below is the code

bool(re.match('.._.. abc_xycompanies_........_._zip(001)','23_61 abc_xycompanies_20201212_1_zip(001)'))

The above code returns False, but if i change it to below then it is returning True. Dont know why but value inside the zip() is not getting matched.

bool(re.match('.._.. abc_xycompanies_........_._zip()','23_61 abc_xycompanies_20201212_1_zip()'))

How can i resolve this issue.

1

There are 1 best solutions below

1
On

Parentheses have special meaning in regex, so you need to escape them in your case, to indicate you mean the specific parentheses symbols. Note:

>>> bool(re.match('zip\\(123\\)','zip(123)'))
True

P.S. Both your examples didn't match by me, so you might have some other issue as well.