开发者

Need regex for all HTML <input /> tags which lack a specific attribute

开发者 https://www.devze.com 2023-01-11 03:29 出处:网络
I need a regex to match all self-closing <input /> tags which lacks a type attribute. For example, I want to find the开发者_开发知识库se:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消