matching any character including newlines in a Python regex subexpression, not globally

前端 未结 3 417
难免孤独
难免孤独 2020-12-01 15:47

I want to use re.MULTILINE but NOT re.DOTALL, so that I can have a regex that includes both an \"any character\" wildcard and the normal . wild

3条回答
  •  生来不讨喜
    2020-12-01 16:00

    [^]
    

    In regex, brackets contains a list and/or range of possible values for one matching character. If that list is empty, I mean [], any character of string can't match it.

    Now, the caret in front of that list and/or range, negates those permitted values. So, in front of an empty list, any character (including newline) will match it.

提交回复
热议问题