【问题标题】:altering a substring of a string Java更改字符串 Java 的子字符串
【发布时间】:2013-10-29 12:00:39
【问题描述】:

如何使用 replaceAll() 更改字符串的子字符串 例如使用正则表达式“1[a-z]+”(用“X”分割)和代码:

"this is an example 1one"

应该产生:

"this is an example 1Xone"

【问题讨论】:

    标签: string replace expression substring


    【解决方案1】:

    试试这个:

    class Test {
      public static void main(String[] args) {
        String str = "this is an example 1one";
        str = str.replaceAll("1([a-z]+)", "1X$1");
        System.out.println(str);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      相关资源
      最近更新 更多