I need a regex to match all self-closing <input />
tags which lacks a type attribute.
For example, I want to find the开发者_开发知识库se:
<input size="1" />
<input name="test" />
But not this:
<input type="radio" />
Please note, this should be adaptable for any single attribute. I am just using type here as an example.
FYI, I am performing a search across 1000s of .html files using AstroGrep.
You can assume that the attribute is well-formed, with equals sign and double quotes.
<input(?:\s+(?!type=)\w+="[^"]*")*\s*/>
That should work if AstroGrep's regex flavor isn't too exotic. I can't find an online reference for it.
I don't know what is AstroGrep, but if it has negative look-ahead, you could just do
(?!\<input(?:[[:space:]]+[a-zA-Z0-9_]+="[^"]*")*(?:[[:space:]]+type="[^"]*"))<input(?:[[:space:]]+[a-zA-Z0-9_]+="[^"]*")*[[:space:]]*/>
Without it, it is much more laborious.
精彩评论