TychoTheTaco TychoTheTaco - 1 year ago 88
Android Question

Highlight IP address in string

Suppose I have the following string

User connected to this AP
. I want to replace the IP address in there with
<font color='red'>"+"</font>
so that I can change it's color. What is the best way to achieve this?

Answer Source

This is the full code based on TimĀ“s answer:

String input = "User connected to this AP";
String regex = "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})";
String output = input.replaceAll(regex, "<font color='red'>$0</font>");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download