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

后端 未结 12 2312
旧时难觅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:25

    What you need is look around assertion like .+? (?=abc).

    See: Lookahead and Lookbehind Zero-Length Assertions

    Be aware that [abc] isn't the same as abc. Inside brackets it's not a string - each character is just one of the possibilities. Outside the brackets it becomes the string.

提交回复
热议问题