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 answers

my 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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -