Package com.microej.stringregex
Class StringRegexExtension
- java.lang.Object
-
- com.microej.stringregex.StringRegexExtension
-
-
Constructor Summary
Constructors Constructor Description StringRegexExtension()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanmatches(String self, String regex)Tells whether or not this string matches the given regular expression.static StringreplaceAll(String self, String regex, String replacement)Replaces each substring of this string that matches the given regular expression with the given replacement.static StringreplaceFirst(String self, String regex, String replacement)Replaces the first substring of this string that matches the given regular expression with the given replacement.static String[]split(String self, String regex)Splits this string around matches of the given regular expression.
-
-
-
Method Detail
-
replaceFirst
public static String replaceFirst(String self, String regex, String replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement.- Parameters:
self- the original string, corresponding tothis, to replace the first match fromregex- the regular expression to which this string is to be matchedreplacement- the string to be substituted for the first match- Returns:
- The resulting String
- Throws:
PatternSyntaxException- if the regular expression's syntax is invalid
-
replaceAll
public static String replaceAll(String self, String regex, String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.- Parameters:
self- the original string, corresponding tothis, to replace matches fromregex- the regular expression to which this string is to be matchedreplacement- the string to be substituted for each match- Returns:
- The resulting String
- Throws:
PatternSyntaxException- if the regular expression's syntax is invalid
-
split
public static String[] split(String self, String regex)
Splits this string around matches of the given regular expression. Trailing empty strings are not included in the resulting array.- Parameters:
self- the original string, corresponding tothis, to be splitregex- the delimiting regular expression- Returns:
- the array of strings computed by splitting this string around matches of the given regular expression
- Throws:
PatternSyntaxException- if the regular expression's syntax is invalid
-
matches
public static boolean matches(String self, String regex)
Tells whether or not this string matches the given regular expression.- Parameters:
self- the original string, corresponding tothis, to check for matchingregex- the regular expression to which this string is to be matched- Returns:
- true if, and only if, this string matches the given regular expression
- Throws:
PatternSyntaxException- if the regular expression's syntax is invalid
-
-