Pattern Class
Namespace
Pattern Methods
The following are methods for Pattern.
compile(regExp)
Signature
public static Pattern compile(String regExp)
Parameters
- regExp
- Type: String
Return Value
Type: System.Pattern
matches(regExp, stringtoMatch)
Signature
public static Boolean matches(String regExp, String stringtoMatch)
Return Value
Type: Boolean
Usage
If a pattern is to be used multiple times, compiling it once and reusing it is more efficient than invoking this method each time.
Example
Note that the following code example:
produces the same result as this code example:
pattern()
Signature
public String pattern()
Return Value
Type: String
quote(yourString)
Signature
public static String quote(String yourString)
Parameters
- yourString
- Type: String
Return Value
Type: String
Usage
Metacharacters (such as $ or ^) and escape sequences in the input string are treated as literal characters with no special meaning.
split(regExp)
Signature
public String[] split(String regExp)
Parameters
- regExp
- Type: String
Return Value
Type: String[]
Usage
The substrings are placed in the list in the order in which they occur in the String. If regExp does not match the pattern, the resulting list has just one element containing the original String.
split(regExp, limit)
Signature
public String[] split(String regExp, Integer limit)
Parameters
- regExp
- Type: String
- limit
- Type: Integer
- (Optional) Controls the number of times the pattern is applied and therefore affects
the length of the list.
- If limit is greater than zero:
- The pattern is applied a maximum of (limit – 1) times.
- The list’s length is no greater than limit.
- The list’s last entry contains all input beyond the last matched delimiter.
- If limit is non-positive, the pattern is applied as many times as possible, and the list can have any length.
- If limit is zero, the pattern is applied as many times as possible, the list can have any length, and trailing empty strings are discarded.
- If limit is greater than zero:
Return Value
Type: String[]