提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用正则表达式替换字符串
import java.util.regex.Matcher; /* NowJava.com - 时 代 Java */ import java.util.regex.Pattern; public class Main { private static String REGEX = "dog"; private static String INPUT = "The dog says meow. " + "All dogs say meow."; private static String REPLACE = "cat"; public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); // get a matcher object Matcher