Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Help in building regurlar expression

$
0
0

Hi,

 Input:

<xhtml>&lt;img src="" /&gt;</xhmtl><xhtml>&lt;img src="" pml="testpml" data-pml="xxads1"  /&gt;&lt;img src="" pml="xxads2" /&gt;</xhmtl><xhtml>&lt;img src="" pml="xxads3" /&gt;</xhtml><xhtml>&lt;img src="" test="" test2="" data-pml="xxads4" pml="4testing" /&gt; test3=""</xhtml><xhtml>&lt;img data-pml="xxads5" /&gt; test3=""</xhtml><xhtml>&lt;img alt="" src="" pml="xxads6" /&gt; test3=""</xhtml><xhtml>&lt;img src="" /&gt;&lt;img src="" pml="xxads7" /&gt;</xhmtl><xhtml>

Output:

<xhtml>&lt;img src="" /&gt;</xhmtl><xhtml>testpmlxxads2</xhmtl><xhtml>xxads3</xhtml><xhtml>4testing test3=""</xhtml><xhtml>xxads5 test3=""</xhtml><xhtml>xxads6 test3=""</xhtml><xhtml>&lt;img src="" /&gt;xxads7</xhmtl><xhtml>

Need to replace the entire img tag with the "pml" or the "data-pml" attibute value or both attributs.

&lt;img src="" pml="xxads1" &gt; need to be replaced with xxads1.

&lt;img  pml="xxads1" src="" &gt; need to be replaced with xxads1.

&lt;img data-pml="xxads3" /&gt; need to be replaced with xxads3

&lt;img src="" data-pml="xxads3" /&gt; need to be replaced with xxads3

&lt;img src="" pml="testpml" data-pml="xxads1"  /&gt; need to be replaced with testpml

&lt;img src="" test="" test2="" data-pml="xxads4" pml="4testing" /&gt; need to be replaced with 4testing.

If there is  no pml or data-pml attribute in img tag, the img tag should be left as it is.

If there are both pml and data-pml attributes in img tag, irrespective of order of occurrence, the img should be replaced with the value in pml attribute.

Need to build a regular expression and use regex.replace to replace values wherever

My apologies. There is a change in our requirement.

Thanks.


Viewing all articles
Browse latest Browse all 8156


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>