简体   繁体   English

Netbeans多行正则表达式搜索

[英]Netbeans Multi-line Regular Expression Search

I'm trying to search for all the HTML input tags with a type of 'text' inside Netbeans 6.9. 我正在尝试在Netbeans 6.9中搜索所有带有“text”类型的HTML输入标签。

Does Netbeans support searching for string using regular expressions with different search criteria spread across multiple lines or does it only work within a single line? Netbeans是否支持使用分布在多行中的不同搜索条件的正则表达式搜索字符串,还是仅在一行内工作?

This regular expression 这个正则表达式

<input.*type=['"]text['"].*/>

works when the entire tag and its attributes are written in a single line like this 当整个标记及其属性像这样写在一行中时起作用

<input name="data[something]" id="some_id" value="some_value" type="text" />

But because I avoid writing long lines of code and break them as such 但是因为我避免编写长行代码并将其打破

<input name="data[something]" id="some_id"
       value="some_value" type="text" />

the same regular expression does not work. 相同的正则表达式不起作用。

Is there a way this could be achieved? 有没有办法实现这一目标?

By default, the . 默认情况下. metacharacter doesn't match newlines. 元字符与换行符不匹配。 There should be an option called "Single-line" or "DOTALL" or similar, that lets the dot match every character. 应该有一个名为“单行”或“DOTALL”或类似的选项,让点匹配每个字符。 Or you could add (?s) to the beginning of the regex and get the same effect for just that regex. 或者你可以将(?s)添加到正则表达式的开头,并为正则表达式获得相同的效果。

But it would be better to replace the .* with [^<>]* . 但用[^<>]*替换.*会更好。 In DOTALL mode, .* will try to gobble up the whole rest of the document, resulting in slow performance and/or incorrect matches, but [^<>]* will never try to match beyond the end of the tag. 在DOTALL模式下, .*将尝试吞噬文档的其余部分,导致性能降低和/或匹配错误,但[^<>]*将永远不会尝试匹配超出标记的末尾。

By the way, if you're using ['|"] to match a single-quote or a double-quote, get rid of the | . "OR" is implied in a character class, so you only need ['"] (the | would simply match a literal | ). 顺便说一下,如果你使用['|"]来匹配单引号或双引号,那么摆脱| 。”OR“隐含在一个字符类中,所以你只需要['"]|将简单地匹配文字| )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM