javascript regex - add closing img tag -
javascript regex - add closing img tag -
i need add together closing image tag. current html:
<img class="logoemail" src="/images/logopdf.png">
what want:
<img class="logoemail" src="/images/logopdf.png"/>
how can that?
myinput ='<img class="example1" src="/images/example1.png">'; myinput += '<img class="example2" src="/images/example2.png"/>'; result = myinput.replace(/(<img("[^"]*"|[^\/">])*)>/g, "$1/>");
explanation of regex:
<img
start
"[^"]*"
string within tag. may contain /
character.
[^\/">]
else (not string, not /
, not end of tag
>
end of img tag
this match unfinished tags, , replace whole thing, plus />
as said before not bulletproof, there no regex work 100%.
javascript regex
Comments
Post a Comment