Android replace with regex

前端 未结 1 909
执笔经年
执笔经年 2021-02-14 19:51

I have a string in Android. I would like to wrap all the instances of 4 or more continuous digits with some html. I imagine this will be done with regex, but I have a hard time

1条回答
  •  有刺的猬
    2021-02-14 19:59

    This will do it:

    String input = "My phone is 1234567890 and my office is 7894561230";
    String regex = "\\d{4,}";
    String output = input.replaceAll(regex, "$0");
    System.out.println(output);
    

    0 讨论(0)
提交回复
热议问题