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.
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?
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" valu开发者_Python百科e="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. Or you could add (?s)
to the beginning of the regex and get the same effect for just that regex.
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.
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 |
).
精彩评论