I have the next string:
<a href="https://lac.wetlands.org/" class="com-link" target="_blank"><mark class="hl_yellow"><b>Fundación Humedales/Wetlands International:</b></mark></a><mark class="hl_yellow"><b> </b></mark><a href="https://twitter.com/fundachumedales?lang=en" class="com-link" target="_blank">Twitter </a>/ <a href="https://es-la.facebook.com/fundacion.humedales/" class="com-link" target="_blank">Facebook</a> / Instagram. Por el Día de los Humedales, junto al Museo Scasso lanzó <a href="https://www.youtube.com/watch?v=xl0lgozO_HU&feature=youtu.be" class="com-link" target="_blank">este video</a>
I need to match all the classes of the tags < a > only.
I have this regex:
(?:class|className)=(?:["']\W \s*(?:\w )()?"'['"]/g;
But its apply in every tag (Like < mark >). In need to apply only in tags a but i cant get it. Any help ?strong text
CodePudding user response:
This would match the class attribute in a
tags:
(?<=<a)(?:.(?!<\/a>))*?class="([^"]*)
The Key part is (?:.(?!<\/a>))*?
where you check that </a>
doesn't occur before finding classe="