Regex for Eclipse/Flash Builder File Search for comments?
In Eclipse (and Flash/Flex Builder) you get the option with Ctrl+Shift+F to do a f开发者_如何学运维ile search and look for a regular expression. Would be a real handy thing to know.
I want to find the word negate if it appears in a Flex/java comment like the following:
// It was negated because
or
/*
The negate option was....
*/
or
/**
* We have to negate the value
*/
Any ideas? Will test them out at http://www.regexplanet.com/simple/index.html
Matching only the word "negate" is tricky, because you would need a lookbehind expression (such as (?<=\/\/.*)negate
to match only "negate"s preceded by //
and any number of characters), but these are supposed to have a fixed length - which we cannot know, since "negate" could really appear anywhere inside a comment. I'm afraid I don't know any other way to match single words inside other text.
However, you can find entire comments containing "negate" in eclipse using this RegEx:
((//.*negate.*$)|(/\*(.|\r|\n)*negate(.|\r|\n)*\*/))
Edit: removed some unnecessary backslashes
This should do it for you I believe:
(?://.|/*.\s*.*)negate
精彩评论