No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Pattern Class
Namespace
Pattern Methods
The following are methods for Pattern.
compile(String)
Signature
public static Pattern compile(String regExp)
Parameters
- regExp
- Type: String
Return Value
Type: System.Pattern
matches(String, String)
Signature
public static Boolean matches(String regExp, String s)
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:
1Pattern.matches(regExp, input);produces the same result as this code example:
1Pattern.compile(regex).
2matcher(input).matches();pattern()
Signature
public String pattern()
Return Value
Type: String
quote(String)
Signature
public static String quote(String s)
Parameters
- s
- 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(String)
Signature
public String[] split(String s)
Parameters
- s
- 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 s does not match the pattern, the resulting list has just one element containing the original String.
split(String, Integer)
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 at most limit - 1 times, the list's length is no greater than limit, and the list's last entry contains all input beyond the last matched delimiter.
- If limit is non-positive then the pattern is applied as many times as possible and the list can have any length.
- If limit is zero then the pattern is applied as many times as possible, the list can have any length, and trailing empty strings are discarded.
Return Value
Type: String[]