Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search for a Java string in Eclipse?

Tags:

java

eclipse

I need to search for instances of a character sequence in a Java string using Eclipse. Is there an easy way or regex to do this?

Example: Search for Eggs should match

String str = "Eggs and toast."

and not match

Eggs e = new Eggs()
like image 785
Garrett Hall Avatar asked Mar 26 '12 13:03

Garrett Hall


3 Answers

  • Under search menu (press ^H)
  • Go to File Search tab
  • check Regular expression radio button
  • Enter text ".*?Eggs[^"]*" in Containing Text field on top
  • Click on Search button
like image 93
anubhava Avatar answered Nov 02 '22 23:11

anubhava


Would something like this work for you?

\".*Eggs.*\"
like image 30
Mike Bockus Avatar answered Nov 03 '22 00:11

Mike Bockus


In general this is very hard because what you want to search for is not "regular" in the sense of "regular expression".

One of the answers you've had suggests:

\".*Eggs.*\"

which is pretty good, but will still match, for example,

System.out.println("There are " + new Eggs().count() + " eggs");

In general, there is not going to be a regular expression which does exactly what you want.

like image 32
dty Avatar answered Nov 02 '22 22:11

dty