Witam,
męczę się z jedym wyrażeniem regularnych i za ..chiny nie mogę uzyskać pożądanego efektu. Co ciekawe na niektórych regex testerach (np. http://regexhero.net/tester/), to co mam, działa poprawnie, ale już w C# nie..
Mam taki tekst wejściowy:
<p class=MsoNormal style='margin-bottom:12.0pt;background:white'><span style='font-family:"Calibri",sans-serif;color:black'><img width=19 height=19 id="_x0000_i1025" src="cid:[email protected]" alt="😳"><o:p></o:p></span></p><div id=c1-id-7><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Calibri",sans-serif;color:#727272'>&nbs<br id=c1-id-14><br id=c1-id-15><br><o:p></o:p></span></p><table class=MsoNormalTable border=0 cellpadding=0 width=450 style='width:337.5pt' id=c1-id-17><tr id=c1-id-23><td width=34 style='width:25.5pt;padding:.75pt .75pt .75pt .75pt' id=c1-id-24><p id=c1-id-25><span style='font-family:"Arial",sans-serif'><a href="#" id=c1-id-26><span style='text-decoration:none'><img border=0 width=55 height=74 id=c1-id-27 src="cid:[email protected]" alt=pgesimg></span></a><o:p></o:p></span></p></td><td width=17 style='width:12.75pt;padding:.75pt .75pt .75pt .75pt' id=c1-id-28><p id=c1-id-29><span style='font-family:"Arial",sans-serif'> <o:p></o:p></span></p></td><td valign=top style='padding:.75pt .75pt .75pt .75pt' id=c1-id-30><p id=c1-id-31><span style='font-size:10.0pt;font-family:"Calibri",sans-serif;color:#727272'>Tel.: <br id=c1-id-33>Fax.: <br id=c1-id-34>Kom.: <br id=c1-id-35><a href="mailto:mail"><span style='font-family:"Arial",sans-serif'><o:p></o:p></span></p></td></tr></table></div><p class=MsoNormal style='background:white'><span style='font-family:"Calibri",sans-serif;color:black'><o:p> </o:p></span></p><div><div class=MsoNormal align=center style='text-align:center;background:white'><span style='font-family:"Calibri",sans-serif;color:black'><hr size=2 width="98%" align=center></span></div><div id=divRplyFwdMsg><p class=MsoNormal style='background:white'><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:black'>Od:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:black'> imie<br><b>Wysłane:</b> 9 czerwca 2016 14:00<br><b>Do:</b> ala<br><b>Temat:</b> img</span><span style='font-family:"Calibri",sans-serif;color:black'> <o:p></o:p></span></p><div><p class=MsoNormal style='background:white'><span style='font-family:"Calibri",sans-serif;color:black'> <o:p></o:p></span></p></div></div><div><div id=divtagdefaultwrapper><pstyle='background:white'><span style='font-family:"Calibri",sans-serif;color:black'>img <img border=0 width=19 height=19 id="_x0000_i1028" src="cid:[email protected]" alt="🌂"><o:p></o:p></span></p><div id=c1-id-7><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Calibri",sans-serif;color:#727272'> <br id=c1-id-9>Serdecznie pozdrawiam,<br id=c1-id-10><br id=c1-id-11><strong id=c1-id-13><span style='font-family:"Calibri",sans-serif'>user</span></strong><br id=c1-id-14>Specjalista ds. IT<br id=c1-id-15><br><o:p></o:p></span></p><table class=MsoNormalTable border=0 cellpadding=0 width=450 style='width:337.5pt' id=c1-id-17><tr id=c1-id-23><td width=34 style='width:25.5pt;padding:.75pt .75pt .75pt .75pt' id=c1-id-24><p id=c1-id-25><span style='font-family:"Arial",sans-serif'><a href="url" id=c1-id-26><span style='text-decoration:none'><img border=0 width=55 height=74 id="_x0000_i1029" src="cid:[email protected]" alt=pgesimg></span></a><o:p></o:p></span></p></td><td width=17 style='width:12.75pt;padding:.75pt .75pt .75pt .75pt' id=c1-id-28><p id=c1-id-29><span style='font-family:"Arial",sans-serif'> <o:p></o:p></span></p></td><td valign=top style='padding:.75pt .75pt .75pt .75pt' id=c1-id-30><p id=c1-id-31><span style='font-size:10.0pt;font-family:"Calibri",sans-serif;color:#727272'>Tel.: +48 67 352 00 46 <br id=c1-id-33>Fax.: fax_xyz <br id=c1-id-34>Kom.: mobile_xyz <br id=c1-id-35><a href="mailto:mail"><span style='color:#727272;text-decoration:none'></span></a></span>
Przygotowałem takie wyrażenie (kombinowałem na dziesiątki sposobów, niektóre 'pozornie' działały w testerach online, inne nie. Aktualnie stanąłem na poniższym..)
<img\s(?=.*?\bpgesimg\b)[^>]*>
Powyższym wyrażeniem regularnym chciałbym znaleźć (i docelowo zastąpić) te zdjęcia, które zawierają wyłącznie atrybut alt alt=pgesimg
lub alt="pgesimg"
.
Wynik jaki otrzymuje na ten moment to:
[0][0] =
[1][0] =
[2][0] =
[3][0] =
Testowałem to na stronie https://myregextester.com gdzie wyniki pokrywają się z kodem uruchomionym w projekcie w VS.
Podsumowując: proszę o ratunek jak miałby wyglądać poprawny regex..
pzdr,
agawa