Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Android 中有一个字符串。我想用一些html包装所有4个或更多连续数字的实例。我想这将通过正则表达式完成,但我很难让最基本的正则表达式工作。
有人可以帮我弄这个吗?
我想改:
var input = "My phone is 1234567890 and my office is 7894561230";
至
var output = "My phone is <u>1234567890</u> and my office is <u>7894561230</u>";
这将做到:
String input = "My phone is 1234567890 and my office is 7894561230"; String regex = "\\d{4,}"; String output = input.replaceAll(regex, "<u>$0</u>"); System.out.println(output);