matching parentheses in python regular expression

前端 未结 3 536
礼貌的吻别
礼貌的吻别 2020-12-21 08:05

I have something like

store(s)

ending line like 1 store(s) .. I want to match , it using python regular expression.

I

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 08:32

    In more or less direct reply to your comment

    Try this

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

    The solution is to use re.search instead of re.match as the latter tries to match the whole string with the regexp while the former just tries to find a substring inside of the string that does match the expression.

提交回复
热议问题