How to match “anything up until this sequence of characters” in a regular expression?

后端 未结 12 2156
旧时难觅i
旧时难觅i 2020-11-22 11:51

Take this regular expression: /^[^abc]/. This will match any single character at the beginning of a string, except a, b, or c.

If you add a *

12条回答
  •  长发绾君心
    2020-11-22 12:19

    On python:

    .+?(?=abc) works for the single line case.

    [^]+?(?=abc) does not work, since python doesn't recognize [^] as valid regex. To make multiline matching work, you'll need to use the re.DOTALL option, for example:

    re.findall('.+?(?=abc)', data, re.DOTALL)
    

提交回复
热议问题