基本的に、私はJavaの文字列内の文字列を一致させようとしています。たとえば、「hello!there!hello!」の「hello」をすべてのhelloと一致させたいとします。
私は現在これを持っていますが、機能していません:
if(word.matches(wordToMatch)) {
word = word.replaceAll(wordToMatch, plugin.greenyPhrases.get(wordToMatch));
}
どんな助けでも大歓迎です!
やってみました
String word = "hello!there!hello!";
word = word.replaceAll("hello", "replaced");
編集:完全な文字列クラス表記はこちら:http://docs.oracle.com/javase/6/docs/api/java/lang/String.html
一致する方法で正規表現エンジンを使用する場合は、.* を使用する必要があります。
String word = "hello!there!hello!";
String requestedWord = "hello"
if( word.matches( ".*" + requestedWord + ".*" ) )
{
System.out.println( " This will be printed " );
}
一番
Matcher.find() を使用してこれを行うことができます