Python regex to match text in single quotes, ignoring escaped quotes (and tabs/newlines)

后端 未结 3 522
渐次进展
渐次进展 2020-12-10 07:00

Given a file of text, where the character I want to match are delimited by single-quotes, but might have zero or one escaped single-quote, as well as zero or more tabs and n

3条回答
  •  青春惊慌失措
    2020-12-10 07:24

    You cold try it like this:

    pattern = re.compile(r"menu_item = '(.*?)(?

    It will start matching at the first single quote it finds and it ends at the first single quote not preceded by a backslash. It also captures any newlines and tabs found between the two single quotes.

提交回复
热议问题