Recently I started to refactor a web application project. A lot of HTML tags written in the JSP doesn’t respect the standard defined by W3C.
I want to close all tag not closed.
<img style="border:0px;"
src="target/img/expande.gif"
alt="Expand target information" > // --> this tag is not closed!
So, with this expr I can search all not closed tag:
(?s)<img("[^"]*"|'[^']*'|[^'">/])*>
What should I do for replace the piece of code with /> ?
I assume that you’re using the Eclipse-builtin regex based search&replace on files matching
*.jsp.You need to group the parts of interest with a set of parentheses.
In replacement, each group can be identified by
$nwherenis the 1-based index of the group. So the$1would return you the whole<img ...element without>(and$2would return you the>itself; note that$0returns the entire match).So, once grouped the regex like that, this replacement should do:
Note: preview the replacement carefully. Regex and HTML don’t necessarily go well together.