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()
File Search
tabRegular expression
radio button".*?Eggs[^"]*"
in Containing Text
field on topWould something like this work for you?
\".*Eggs.*\"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With