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

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

    I believe you need subexpressions. If I remember right you can use the normal () brackets for subexpressions.

    This part is From grep manual:

     Back References and Subexpressions
           The back-reference \n, where n is a single digit, matches the substring
           previously matched  by  the  nth  parenthesized  subexpression  of  the
           regular expression.
    

    Do something like ^[^(abc)] should do the trick.

提交回复
热议问题