Regex? Match part of or whole word

前端 未结 5 2048
遥遥无期
遥遥无期 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-26 00:04

    Use the $ to match at the end of a string. For example, the following would match 'potato' only at the end of a string (first example):

    "potato$"
    

    This would match all of your examples:

    "pota[to]{1,2}$"
    

    However, some risk of also matching "potao" or "potaot".

提交回复
热议问题