[英]Regex match when not contains word
I have a question but I can't seem to figure it out. 我有一个问题,但似乎无法解决。 I have been referenceing this article: Regular expression to match a line that doesn't contain a word?
我一直在引用本文: 正则表达式以匹配不包含单词的行?
I am trying to match a URL if the URL doesn't contain 2 dashes: 如果网址不包含2个破折号,我会尝试匹配网址:
Match = /test-doc.html
匹配=
/test-doc.html
Non-Match = /test-doc--help.html
非匹配=
/test-doc--help.html
I have this which works to match and non-match: /(?<a>.(?!\\-\\-))*\\.html
我有这个可以匹配和不匹配的东西:
/(?<a>.(?!\\-\\-))*\\.html
But the group "a" only gets 1 letter vs everything looking back. 但是组“ a”只得到1个字母,而往后看的一切。 I would want group "a" to be "test-doc" rather than just the "c" at the end.
我希望组“ a”成为“ test-doc”,而不是最后的“ c”。
Any suggestions would be appreciated. 任何建议,将不胜感激。
Try a pattern like this: 尝试这样的模式:
/(?<a>(?!.*--).*)\.html
This will match a literal /
followed by zero more of any character, captured in group a
, (but only if that sequence does not contain a literal --
), followed by a literal .html
. 这将匹配文字
/
在组a
捕获的任何字符之后都为零(但前提是该序列不包含文字--
),然后是文字.html
。
For example: 例如:
Dim pattern As String = "/(?<a>(?!.*--).*).html"
Regex.Match("/test-doc-help.html", pattern).Groups("a").Value // "test-doc-help"
Regex.Match("/test-doc--help.html", pattern).Groups("a").Value // ""
You can try your expression in this website 您可以在此网站上尝试表达
http://gskinner.com/RegExr/ http://gskinner.com/RegExr/
And also i think you should use this expression 而且我认为你应该使用这个表达
"\/.*.html"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.