集册 Java实例教程 使用正则表达式替换字符串

使用正则表达式替换字符串

欢马劈雪     最近更新时间:2020-01-02 10:19:05

520
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用正则表达式替换字符串


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 
展开阅读全文