regex - Regular expression for anchor tag in c# -
regex - Regular expression for anchor tag in c# -
this question has reply here:
multiline regular look in c# 2 answersmy anchor tag looks this:-
<a href="/as" title="asd" page="as" name="asd" reference="yes" type="relativepath">as </a>
i tried in way:-
<a [^>]*?>(?<text>.*?)</a>
it working fine when ending anchor tag </a>
supposed in same line. in case ending anchor tag should come in next line.
i need regular look should supports, if ending anchor tag in next line.
suggestions welcome.
you should utilize (?s)
inline option:
(?s)<a [^>]*?>(?<text>.*?)</a>
see demo.
in c#, can utilize regexoptions.singleline
alternative next way:
var input = "<a href=\"/as\" title=\"asd\" page=\"as\" name=\"asd\" reference=\"yes\" type=\"relativepath\">as\r\n</a>"; var regex = new regex(@"<a [^>]*?>(?<text>.*?)</a>", regexoptions.singleline); var result2 = regex.match(input).value;
output:
edit:
this updated version of regex takes business relationship <a>
tags not have attributes (which next impossible, let's imagine :)), , create case-insensitive (who knows, maybe <a href="something_here">
can occur):
var regex = new regex(@"(?i)<a\b[^>]*?>(?<text>.*?)</a>", regexoptions.singleline);
c# regex
Comments
Post a Comment