Is it possible for Eclipse to find results only in string literals?

Suppose I have the following Java code:

public String foo() { // returns foo() String log = "foo() : Logging something!" return log; } 

Can I search in Eclipse for foo() , found only in a string literal, but nowhere in the code? So, in the example here, Eclipse should find only the third event foo() , and not the first, which is the name of the function, and not the second, which is the comment.

Edit: Simple regular expressions will not work because they will find foo() in a string like

 String temp = "literal" + foo() + "another literal" 

But here foo() is the name of the function, not a string literal.

+4
source share
2 answers

You can try this as follows:

 "[^"\n]*foo\\(\\)[^"\n]*" 

You need to get out of the brackets, plus this regex does not match newlines or extra quotes that prevent incorrect matches.

+2
source

Perhaps you need to use regex to look for any cases of foo () between two "?

+1
source

Source: https://habr.com/ru/post/1339047/


All Articles