Matching brackets in python regex

I have something like

store (s)

end of line as 1 store (s) .. I want to match using python regex.

I tried something like re.match('store\(s\)$',text) but it does not work.

EDIT: adding code I tried

import re
s = '1 store(s)'
if re.match('store\(s\)$',s) :
    print('match')

Help Pls.

Thanks Jijoy

+3
source share
3 answers

In a more or less direct response to your comment

try it

import re
s = '1 stores(s)'
if re.match('store\(s\)$',s):
    print('match')

The solution is to use re.searchinstead re.match, as the latter tries to match the entire string with the regular expression, while the former tries to find the substring inside the string that matches the expression.

+6
source

Python , : , ( , Perl )

, .

+1

You thought re.match('(.*)store\(s\)$',text)?

0
source

All Articles