Regular expression: match word not between quotes

后端 未结 5 450
不知归路
不知归路 2021-01-15 00:25

I would like a Python regular expression that matches a given word that\'s not between simple quotes. I\'ve tried to use the (?! ...) but without success.

5条回答
  •  死守一世寂寞
    2021-01-15 00:33

    Capture group 1 of the following regular expression will contain matches of 'foe'.

    r'^(?:[^'\n]|\\')*(?:(?

    Start your engine!

    Python's regex engine performs the following operations.

    ^           : assert beginning of string
    (?:         : begin non-capture group
      [^'\n]    : match any char other than single quote and line terminator
      |         : or
      \\'       : match '\' then a single quote
    )           : end non-capture group   
    *           : execute non-capture group 0+ times
    (?:         : begin non-capture group
      (?

提交回复
热议问题