1

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:

Match = /test-doc.html

Non-Match = /test-doc--help.html

I have this which works to match and non-match: /(?<a>.(?!\-\-))*\.html

But the group "a" only gets 1 letter vs everything looking back. I would want group "a" to be "test-doc" rather than just the "c" at the end.

Any suggestions would be appreciated.

Community
  • 1
  • 1
Chris
  • 336
  • 4
  • 15

2 Answers2

2

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.

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 // ""
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
0

You can try your expression in this website

http://gskinner.com/RegExr/

And also i think you should use this expression

"\/.*.html"
İbrahim Özbölük
  • 3,162
  • 23
  • 20