gpt4 book ai didi

Java正则表达式匹配字符串

转载 作者:行者123 更新时间:2023-12-02 07:47:16 24 4
gpt4 key购买 nike

基本上,我试图在 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");

编辑:这是完整的 String 类符号:http://docs.oracle.com/javase/6/docs/api/java/lang/String.html

关于Java正则表达式匹配字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10656651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com