ductran
ductran

Reputation: 10203

Highlight text in sms android with regex

I want a regular expression to highlight text (underline) in sms like default sms app in android phone.
I have tested for some matched cases:

   Number: 06464, +86786, +84 879, ff765756765thw        /*more than 5 digits */
   Web address: abc.com, http://google.com
   Email address: [email protected]
   Date:   2012.12.02

highlight text
I tried searching in android OS source code but it didn't help. How can I get it?

Upvotes: 0

Views: 1519

Answers (2)

ductran
ductran

Reputation: 10203

Thank to Sana, based on your hint, I found all things in Pattern.java
For example:
- Phone:

public static final String PHONE =
// sdd = space, dot, or dash
"(\\+[0-9]+[\\- \\.]*)?" // +<digits><sdd>*
        + "(\\([0-9]+\\)[\\- \\.]*)?" // (<digits>)<sdd>*
        + "([0-9][0-9\\- \\.][0-9\\- \\.]+[0-9])"; // <digit><digit|sdd>+<digit>

-Email:

public static final String EMAIL_ADDRESS = "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}"
        + "\\@"
        + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}"
        + "("
        + "\\."
        + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+";

Upvotes: 0

Sana
Sana

Reputation: 9915

have you used android:autoLink="web|phone|email" in the TextView which is displaying your numbers or web address or email? But for the date you might want to implement a regex!

Upvotes: 3

Related Questions