If I use this
string showPattern = @"return new_lightox\(this\);"">[a-zA-Z0-9(\s),!\?\-:'&%]+</a>";
MatchCollection showMatches = Regex.Matches(pageSource, showPattern);
I get some matches but I want to get rid of [a-zA-Z0-9(\s),!\?\-:'&%]+and use any char .+
but if do this I get no match at all.
What am I doing wrong?
To let
.match newline, turn on SingleLine/DOTALL mode – either using a flag in the function call (as Abel’s answer shows), or using the inline modifier(?s), like this for the whole expression:Or for just the specific part of it:
It might be better to take that a step further and do this:
Which should prevent the closing
</a>from belonging to a different link.However, you need to be very wary here – it’s not clear what you’re doing overall, but regex is not a good tool for parsing HTML with, and can cause all sorts of problems. Look at using a HTML DOM parser instead, such as HtmlAgilityPack.