Android replaces regex

I have a string in Android. I would like to wrap all instances of 4 or more continuous digits with some html. I suppose this will be done with regex, but it's hard for me to find even the most basic regexes to work with.

Can someone help me?

I would like to change:

var input = "My phone is 1234567890 and my office is 7894561230";

For

var output = "My phone is <u>1234567890</u> and my office is <u>7894561230</u>";
+5
source share
1 answer

This will be done:

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);
+24
source

All Articles