FileDocCategorySizeDatePackage
Regex.javaAPI DocAndroid 1.5 API8197Wed May 06 22:41:56 BST 2009android.text.util

Regex

public class Regex extends Object
hide

Fields Summary
public static final Pattern
TOP_LEVEL_DOMAIN_PATTERN
Regular expression pattern to match all IANA top-level domains. List accurate as of 2007/06/15. List taken from: http://data.iana.org/TLD/tlds-alpha-by-domain.txt This pattern is auto-generated by //device/tools/make-iana-tld-pattern.py
public static final Pattern
WEB_URL_PATTERN
Regular expression pattern to match RFC 1738 URLs List accurate as of 2007/06/15. List taken from: http://data.iana.org/TLD/tlds-alpha-by-domain.txt This pattern is auto-generated by //device/tools/make-iana-tld-pattern.py
public static final Pattern
IP_ADDRESS_PATTERN
public static final Pattern
DOMAIN_NAME_PATTERN
public static final Pattern
EMAIL_ADDRESS_PATTERN
public static final Pattern
PHONE_PATTERN
This pattern is intended for searching for things that look like they might be phone numbers in arbitrary text, not for validating whether something is in fact a phone number. It will miss many things that are legitimate phone numbers.

The pattern matches the following:

  • Optionally, a + sign followed immediately by one or more digits. Spaces, dots, or dashes may follow.
  • Optionally, sets of digits in parentheses, separated by spaces, dots, or dashes.
  • A string starting and ending with a digit, containing digits, spaces, dots, and/or dashes.
Constructors Summary
Methods Summary
public static final java.lang.StringconcatGroups(java.util.regex.Matcher matcher)
Convenience method to take all of the non-null matching groups in a regex Matcher and return them as a concatenated string.

param
matcher The Matcher object from which grouped text will be extracted
return
A String comprising all of the non-null matched groups concatenated together

 // <digit><digit|sdd>+<digit> 

                                                                                                                     
          
        StringBuilder b = new StringBuilder();
        final int numGroups = matcher.groupCount();

        for (int i = 1; i <= numGroups; i++) {
            String s = matcher.group(i);

            System.err.println("Group(" + i + ") : " + s);

            if (s != null) {
                b.append(s);
            }
        }

        return b.toString();
    
public static final java.lang.StringdigitsAndPlusOnly(java.util.regex.Matcher matcher)
Convenience method to return only the digits and plus signs in the matching string.

param
matcher The Matcher object from which digits and plus will be extracted
return
A String comprising all of the digits and plus in the match

        StringBuilder buffer = new StringBuilder();
        String matchingRegion = matcher.group();

        for (int i = 0, size = matchingRegion.length(); i < size; i++) {
            char character = matchingRegion.charAt(i);

            if (character == '+" || Character.isDigit(character)) {
                buffer.append(character);
            }
        }
        return buffer.toString();