Regex not to allow double underscores

后端 未结 3 829
你的背包
你的背包 2021-01-19 01:58

Trying to apply regex for not allowing a string with double underscores

 [a-z][a-z0-9_-]+[^__]

but its failing in many cases like:

3条回答
  •  天涯浪人
    2021-01-19 02:21

    the [^] syntax defines a set of characters so that it matches a character not present in this set

    if you want to match two characters that are not underscores you can use [^_]{2}

    but if you really want to check if a string has two underscores, you better search for two underscores and negate the result

    for example in perl: "ab_" !~ /__/

提交回复
热议问题