Regex 正则表达式不包括8位数字

Regex 正则表达式不包括8位数字,regex,Regex,我有以下URL架构: /test/how-are-you.html /test/hello-how-are-you.html /test/im-fine.html /test/im-fine/how-are-you/ /test/im-fine/hello-how-are-you/ /test/happy-1-day.html /test/thanks-123.html /test/thanks-1234.html /test/thanks-12345.html /test/hoe-are-yo

我有以下URL架构:

/test/how-are-you.html
/test/hello-how-are-you.html
/test/im-fine.html
/test/im-fine/how-are-you/
/test/im-fine/hello-how-are-you/
/test/happy-1-day.html
/test/thanks-123.html
/test/thanks-1234.html
/test/thanks-12345.html
/test/hoe-are-you-10012396.html (always 8 numbers)
/test/im-fine-10012396.html (always 8 numbers)
/test/hello-52345786.html (always 8 numbers)
你能给我一个正则表达式来排除最后3个例子,而包括其余的吗? 我试过类似的东西

^\/test\/?[\w\-]*\/?[\w\-]*([^0-9]{8})\/?
而且失败了;)

最好的,丹尼尔你可以用

^\/test\/(?!.*\d{8}\.html$).*$

详细信息

  • ^
    -字符串的开头
  • \/test\/
    -
    /test/
    字符串
  • (?!.*\d{8}\.html$)
    -如果存在除换行符以外的任何0+字符,请尽可能多,然后是8位数字和字符串末尾的
    .html
    ,匹配失败
  • *$
    -除换行符以外的任何0+字符,尽可能多

@WiktorStribiżew编辑问题。那么,模式有什么问题吗?这是一个好问题,它不起作用,这就是我所知道的。我需要8位数字的[^0-9]。请尝试
^\/test\/(?!.*\d{8}\.html$).$
,请参阅。谢谢,就这样!“我不太熟悉否定展望:”有没有其他选项没有负面前瞻?@ HasC90是,但如果你的工具支持前瞻,它是更短/更干净。@ HasC90 90如果在目标环境中为你工作,请考虑通过点击接受答案。✓ 如果我的回答对你有帮助(请参见),请点击左边(请参见)并向上投票(请参见)。