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

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

    The $ marks the end of a string, so something like this should work: [[^abc]*]$ where you're looking for anything NOT ENDING in any iteration of abc, but it would have to be at the end

    Also if you're using a scripting language with regex (like php or js), they have a search function that stops when it first encounters a pattern (and you can specify start from the left or start from the right, or with php, you can do an implode to mirror the string).

提交回复
热议问题