# Patterns

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Constants](https://developer.android.com/reference/android/util/Patterns#constants)\|[Fields](https://developer.android.com/reference/android/util/Patterns#lfields)\|[Methods](https://developer.android.com/reference/android/util/Patterns#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/util/Patterns#inhmethods)  

# Patterns

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/util/Patterns "View this page in Kotlin")\|Java

`
public


class
Patterns
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-----------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.util.Patterns |

<br />

*** ** * ** ***

Commonly used regular expression patterns.

## Summary

|                                                                                                                                                                                         ### Constants                                                                                                                                                                                         ||
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | [GOOD_IRI_CHAR](https://developer.android.com/reference/android/util/Patterns#GOOD_IRI_CHAR) *This constant was deprecated in API level 24. Deprecated since it does not include all IRI characters defined in RFC 3987*                                                                                                  |
| [String](https://developer.android.com/reference/java/lang/String) | [TOP_LEVEL_DOMAIN_STR](https://developer.android.com/reference/android/util/Patterns#TOP_LEVEL_DOMAIN_STR) *This constant was deprecated in API level 21. Due to the recent profileration of gTLDs, this API is expected to become out-of-date very quickly. Therefore it is now deprecated.*                             |
| [String](https://developer.android.com/reference/java/lang/String) | [TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL](https://developer.android.com/reference/android/util/Patterns#TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL) *This constant was deprecated in API level 21. This API is deprecated. See[TOP_LEVEL_DOMAIN_STR](https://developer.android.com/reference/android/util/Patterns#TOP_LEVEL_DOMAIN_STR).* |

|                                                                                                                                                                                               ### Fields                                                                                                                                                                                                ||
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public static final `[Pattern](https://developer.android.com/reference/java/util/regex/Pattern) | [DOMAIN_NAME](https://developer.android.com/reference/android/util/Patterns#DOMAIN_NAME) <br />                                                                                                                                                                                                      |
| ` public static final `[Pattern](https://developer.android.com/reference/java/util/regex/Pattern) | [EMAIL_ADDRESS](https://developer.android.com/reference/android/util/Patterns#EMAIL_ADDRESS) <br />                                                                                                                                                                                                  |
| ` public static final `[Pattern](https://developer.android.com/reference/java/util/regex/Pattern) | [IP_ADDRESS](https://developer.android.com/reference/android/util/Patterns#IP_ADDRESS) *This field was deprecated in API level 31. Please use[InetAddresses.isNumericAddress(String)](https://developer.android.com/reference/android/net/InetAddresses#isNumericAddress(java.lang.String))instead.* |
| ` public static final `[Pattern](https://developer.android.com/reference/java/util/regex/Pattern) | [PHONE](https://developer.android.com/reference/android/util/Patterns#PHONE) 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.                                         |
| ` public static final `[Pattern](https://developer.android.com/reference/java/util/regex/Pattern) | [TOP_LEVEL_DOMAIN](https://developer.android.com/reference/android/util/Patterns#TOP_LEVEL_DOMAIN) *This field was deprecated in API level 21. This API is deprecated. See[TOP_LEVEL_DOMAIN_STR](https://developer.android.com/reference/android/util/Patterns#TOP_LEVEL_DOMAIN_STR).*               |
| ` public static final `[Pattern](https://developer.android.com/reference/java/util/regex/Pattern) | [WEB_URL](https://developer.android.com/reference/android/util/Patterns#WEB_URL) Regular expression pattern to match most part of RFC 3987 Internationalized URLs, aka IRIs.                                                                                                                         |

|                                                                                                                                                                                                       ### Public methods                                                                                                                                                                                                        ||
|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static final `[String](https://developer.android.com/reference/java/lang/String) | ` `[concatGroups](https://developer.android.com/reference/android/util/Patterns#concatGroups(java.util.regex.Matcher))`(`[Matcher](https://developer.android.com/reference/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. |
| ` static final `[String](https://developer.android.com/reference/java/lang/String) | ` `[digitsAndPlusOnly](https://developer.android.com/reference/android/util/Patterns#digitsAndPlusOnly(java.util.regex.Matcher))`(`[Matcher](https://developer.android.com/reference/java/util/regex/Matcher)` matcher) ` Convenience method to return only the digits and plus signs in the matching string.                               |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Constants

### GOOD_IRI_CHAR

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final String GOOD_IRI_CHAR
```

<br />

**This constant was deprecated in API level 24.**   
Deprecated since it does not include all IRI characters defined in RFC 3987

Kept for backward compatibility reasons.

<br />

Constant Value: "a-zA-Z0-9 -퟿豈-﷏ﷰ-￯"  

### TOP_LEVEL_DOMAIN_STR

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final String TOP_LEVEL_DOMAIN_STR
```

<br />

**This constant was deprecated in API level 21.**   
Due to the recent profileration of gTLDs, this API is expected to become out-of-date very quickly. Therefore it is now deprecated.

Regular expression to match all IANA top-level domains. List accurate as of 2011/07/18. List taken from: http://data.iana.org/TLD/tlds-alpha-by-domain.txt This pattern is auto-generated by frameworks/ex/common/tools/make-iana-tld-pattern.py

<br />

Constant Value: "((aero\|arpa\|asia\|a\[cdefgilmnoqrstuwxz\])\|(biz\|b\[abdefghijmnorstvwyz\])\|(cat\|com\|coop\|c\[acdfghiklmnoruvxyz\])\|d\[ejkmoz\]\|(edu\|e\[cegrstu\])\|f\[ijkmor\]\|(gov\|g\[abdefghilmnpqrstuwy\])\|h\[kmnrtu\]\|(info\|int\|i\[delmnoqrst\])\|(jobs\|j\[emop\])\|k\[eghimnprwyz\]\|l\[abcikrstuvy\]\|(mil\|mobi\|museum\|m\[acdeghklmnopqrstuvwxyz\])\|(name\|net\|n\[acefgilopruz\])\|(org\|om)\|(pro\|p\[aefghklmnrstwy\])\|qa\|r\[eosuw\]\|s\[abcdeghijklmnortuvyz\]\|(tel\|travel\|t\[cdfghjklmnoprtvwz\])\|u\[agksyz\]\|v\[aceginu\]\|w\[fs\]\|(δοκιμή\|испытание\|рф\|срб\|טעסט\|آزمایشی\|إختبار\|الاردن\|الجزائر\|السعودية\|المغرب\|امارات\|بھارت\|تونس\|سورية\|فلسطين\|قطر\|مصر\|परीक्षा\|भारत\|ভারত\|ਭਾਰਤ\|ભારત\|இந்தியா\|இலங்கை\|சிங்கப்பூர்\|பரிட்சை\|భారత్\|ලංකා\|ไทย\|テスト\|中国\|中國\|台湾\|台灣\|新加坡\|测试\|測試\|香港\|테스트\|한국\|xn\\-\\-0zwm56d\|xn\\-\\-11b5bs3a9aj6g\|xn\\-\\-3e0b707e\|xn\\-\\-45brj9c\|xn\\-\\-80akhbyknj4f\|xn\\-\\-90a3ac\|xn\\-\\-9t4b11yi5a\|xn\\-\\-clchc0ea0b2g2a9gcd\|xn\\-\\-deba0ad\|xn\\-\\-fiqs8s\|xn\\-\\-fiqz9s\|xn\\-\\-fpcrj9c3d\|xn\\-\\-fzc2c9e2c\|xn\\-\\-g6w251d\|xn\\-\\-gecrj9c\|xn\\-\\-h2brj9c\|xn\\-\\-hgbk6aj7f53bba\|xn\\-\\-hlcj6aya9esc7a\|xn\\-\\-j6w193g\|xn\\-\\-jxalpdlp\|xn\\-\\-kgbechtv\|xn\\-\\-kprw13d\|xn\\-\\-kpry57d\|xn\\-\\-lgbbat1ad8j\|xn\\-\\-mgbaam7a8h\|xn\\-\\-mgbayh7gpa\|xn\\-\\-mgbbh1a71e\|xn\\-\\-mgbc0a9azcg\|xn\\-\\-mgberp4a5d4ar\|xn\\-\\-o3cw4h\|xn\\-\\-ogbpf8fl\|xn\\-\\-p1ai\|xn\\-\\-pgbs0dh\|xn\\-\\-s9brj9c\|xn\\-\\-wgbh1c\|xn\\-\\-wgbl6a\|xn\\-\\-xkc2al3hye2a\|xn\\-\\-xkc2dl3a5ee0h\|xn\\-\\-yfro4i67o\|xn\\-\\-ygbi2ammx\|xn\\-\\-zckzah\|xxx)\|y\[et\]\|z\[amw\])"  

### TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final String TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL
```

<br />

**This constant was deprecated in API level 21.**   
This API is deprecated. See[TOP_LEVEL_DOMAIN_STR](https://developer.android.com/reference/android/util/Patterns#TOP_LEVEL_DOMAIN_STR).

Regular expression to match all IANA top-level domains for WEB_URL. List accurate as of 2011/07/18. List taken from: http://data.iana.org/TLD/tlds-alpha-by-domain.txt This pattern is auto-generated by frameworks/ex/common/tools/make-iana-tld-pattern.py

<br />

Constant Value: "(?:(?:aero\|arpa\|asia\|a\[cdefgilmnoqrstuwxz\])\|(?:biz\|b\[abdefghijmnorstvwyz\])\|(?:cat\|com\|coop\|c\[acdfghiklmnoruvxyz\])\|d\[ejkmoz\]\|(?:edu\|e\[cegrstu\])\|f\[ijkmor\]\|(?:gov\|g\[abdefghilmnpqrstuwy\])\|h\[kmnrtu\]\|(?:info\|int\|i\[delmnoqrst\])\|(?:jobs\|j\[emop\])\|k\[eghimnprwyz\]\|l\[abcikrstuvy\]\|(?:mil\|mobi\|museum\|m\[acdeghklmnopqrstuvwxyz\])\|(?:name\|net\|n\[acefgilopruz\])\|(?:org\|om)\|(?:pro\|p\[aefghklmnrstwy\])\|qa\|r\[eosuw\]\|s\[abcdeghijklmnortuvyz\]\|(?:tel\|travel\|t\[cdfghjklmnoprtvwz\])\|u\[agksyz\]\|v\[aceginu\]\|w\[fs\]\|(?:δοκιμή\|испытание\|рф\|срб\|טעסט\|آزمایشی\|إختبار\|الاردن\|الجزائر\|السعودية\|المغرب\|امارات\|بھارت\|تونس\|سورية\|فلسطين\|قطر\|مصر\|परीक्षा\|भारत\|ভারত\|ਭਾਰਤ\|ભારત\|இந்தியா\|இலங்கை\|சிங்கப்பூர்\|பரிட்சை\|భారత్\|ලංකා\|ไทย\|テスト\|中国\|中國\|台湾\|台灣\|新加坡\|测试\|測試\|香港\|테스트\|한국\|xn\\-\\-0zwm56d\|xn\\-\\-11b5bs3a9aj6g\|xn\\-\\-3e0b707e\|xn\\-\\-45brj9c\|xn\\-\\-80akhbyknj4f\|xn\\-\\-90a3ac\|xn\\-\\-9t4b11yi5a\|xn\\-\\-clchc0ea0b2g2a9gcd\|xn\\-\\-deba0ad\|xn\\-\\-fiqs8s\|xn\\-\\-fiqz9s\|xn\\-\\-fpcrj9c3d\|xn\\-\\-fzc2c9e2c\|xn\\-\\-g6w251d\|xn\\-\\-gecrj9c\|xn\\-\\-h2brj9c\|xn\\-\\-hgbk6aj7f53bba\|xn\\-\\-hlcj6aya9esc7a\|xn\\-\\-j6w193g\|xn\\-\\-jxalpdlp\|xn\\-\\-kgbechtv\|xn\\-\\-kprw13d\|xn\\-\\-kpry57d\|xn\\-\\-lgbbat1ad8j\|xn\\-\\-mgbaam7a8h\|xn\\-\\-mgbayh7gpa\|xn\\-\\-mgbbh1a71e\|xn\\-\\-mgbc0a9azcg\|xn\\-\\-mgberp4a5d4ar\|xn\\-\\-o3cw4h\|xn\\-\\-ogbpf8fl\|xn\\-\\-p1ai\|xn\\-\\-pgbs0dh\|xn\\-\\-s9brj9c\|xn\\-\\-wgbh1c\|xn\\-\\-wgbl6a\|xn\\-\\-xkc2al3hye2a\|xn\\-\\-xkc2dl3a5ee0h\|xn\\-\\-yfro4i67o\|xn\\-\\-ygbi2ammx\|xn\\-\\-zckzah\|xxx)\|y\[et\]\|z\[amw\]))"

## Fields

### DOMAIN_NAME

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Pattern DOMAIN_NAME
```

<br />

<br />

### EMAIL_ADDRESS

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Pattern EMAIL_ADDRESS
```

<br />

<br />

### IP_ADDRESS

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Pattern IP_ADDRESS
```

<br />

**This field was deprecated in API level 31.**   
Please use[InetAddresses.isNumericAddress(String)](https://developer.android.com/reference/android/net/InetAddresses#isNumericAddress(java.lang.String))instead.

Kept for backward compatibility reasons. It does not match IPv6 addresses.

<br />

### PHONE

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Pattern PHONE
```

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.

<br />

<br />

### TOP_LEVEL_DOMAIN

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Pattern TOP_LEVEL_DOMAIN
```

<br />

**This field was deprecated in API level 21.**   
This API is deprecated. See[TOP_LEVEL_DOMAIN_STR](https://developer.android.com/reference/android/util/Patterns#TOP_LEVEL_DOMAIN_STR).

Regular expression pattern to match all IANA top-level domains.

<br />

### WEB_URL

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Pattern WEB_URL
```

Regular expression pattern to match most part of RFC 3987 Internationalized URLs, aka IRIs.

<br />

## Public methods

### concatGroups

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final String concatGroups (Matcher matcher)
```

Convenience method to take all of the non-null matching groups in a regex Matcher and return them as a concatenated string.

<br />

|                                        Parameters                                         ||
|-----------|--------------------------------------------------------------------------------|
| `matcher` | `Matcher`: The Matcher object from which grouped text will be extracted <br /> |

|                                                                         Returns                                                                         ||
|--------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | A String comprising all of the non-null matched groups concatenated together <br /> |

### digitsAndPlusOnly

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final String digitsAndPlusOnly (Matcher matcher)
```

Convenience method to return only the digits and plus signs in the matching string.

<br />

|                                          Parameters                                          ||
|-----------|-----------------------------------------------------------------------------------|
| `matcher` | `Matcher`: The Matcher object from which digits and plus will be extracted <br /> |

|                                                                Returns                                                                 ||
|--------------------------------------------------------------------|--------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | A String comprising all of the digits and plus in the match <br /> |