模式引用会产生过多的\ Q和\ E.

时间:2015-11-17 22:25:49

标签: java regex for-loop replace

用ArrayList S中的任何模式替换字符串X时,新消息N会产生过多的正则表达式引号,\ Q和\ E。

一旦它通过消息读取或实施某种倒计时以阻止垃圾的引用报价,它们是否有某种方式来打破循环?

代码:

prepareForSegue

输出正在运行:

    List<String> index = new ArrayList<String>()
    index.add("This");
    index.add("test");
    String x = "This is a random test phrase";
    for (String s : index)
    {
        x = Pattern.quote(x);
        String new = x.replaceAll("(?i)"+s, "*"); //edit: forgot type
    }
    System.out.println(new);

1 个答案:

答案 0 :(得分:0)

这是你想要的吗?我不确定你期望的输出。

    List<String> index = new ArrayList<String>();
    index.add("This");
    index.add("test");
    String x = "This is a random test phrase";
    for (String s : index)
    {
        x = x.replaceAll(s, "*");
    }
    System.out.println(x);

生成* is a random * phrase