Reputation: 840
Basically I'm trying to match a string inside of a string in Java. For example, I'd want to match "hello" in "hello!there!hello!", matching all of the hellos.
I currently have this but it's not working:
if(word.matches(wordToMatch)) {
word = word.replaceAll(wordToMatch, plugin.greenyPhrases.get(wordToMatch));
}
Any help would be majorly appreciated!
Upvotes: 0
Views: 656
Reputation: 148
If you want to use the regex engine through the matches method, you need to use .*
String word = "hello!there!hello!";
String requestedWord = "hello"
if( word.matches( ".*" + requestedWord + ".*" ) )
{
System.out.println( " This will be printed " );
}
Best
Upvotes: 0
Reputation: 2134
have you tried
String word = "hello!there!hello!";
word = word.replaceAll("hello", "replaced");
edit: heres the full String class notation : http://docs.oracle.com/javase/6/docs/api/java/lang/String.html
Upvotes: 2