0

I would like to exclude the first group from my regex so that the result is no longer inside. Could someone help me please?

This is my regex: href="(.*)(?=(?:"))

And that for example the text: fdlasjfkldjfksdjhref="contact"adskldfjaskfjak

Now I want this result: contact

I have no Idea what I do wrong...

I thank you now for your help!

2 Answers2

2

You could use a positive lookbehind (?<= to assert what is on the left side is href=", then match not a double quote using a negated character class [^"]+followed by a positive lookahead (?= to assert that what follows is a double quote.

(?<=href=")[^"]+(?=")

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
-1

I find this site useful to test out regex and matching patterns http://www.regexplanet.com/advanced/dotnet/index.html

I input your expression and test string examples and it shows the .NET string version needs to be

"href=\"(.*)(?=(?:\"))"

Note the escaped double quotes.

Groups[1] returns your desired text

Fuzzybear
  • 1,388
  • 2
  • 25
  • 42