Regex? Match part of or whole word

前端 未结 5 1967
遥遥无期
遥遥无期 2021-01-25 23:33

I was wondering if it\'s possible to use regex with python to capture a word, or a part of the word (if it\'s at the end of the string).

Eg:
target word - potato

5条回答
  •  面向向阳花
    2021-01-25 23:58

    import re
    patt = re.compile(r'(p|po|pot|pota|potat|potato)$')
    patt.search(string)
    

    I was tempted to use r'po?t?a?t?o?$', but that would also match poto or pott.

提交回复
热议问题