1

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.

Mrinal
  • 105
  • 7

1 Answers1

1

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.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
  • Thanks it worked. P.S There was an issue with the code which i had pasted have corrected it – Mrinal Jul 16 '21 at 08:11