Package dev.comfast.rgx
Class RgxApi
java.lang.Object
dev.comfast.rgx.RgxApi
Provide fluent interface for common Regex operations. Most cases can be done in one line with proper error handling:
Usage example:
rgx("\\d+").match("abc123xxx456").get() // returns "123"
rgx("\\d+").match("abc123xxx456").matchAllAsString() // returns entire matches: ["123", "456"]
rgx("\\d(\\d\\d)").match("abc123xxx456").matchAllAsString(1) // returns groups number '1': ["23", "56"]
rgx("\\d(\\d\\d)").match("abc123xxx456").group(1) // returns "23"
rgx("ooo").match("abc123xxx456").isPresent() // returns false;
// Also throw detailed errors:
rgx("yyy").match("abc123xxx456").throwIfEmpty()... // throws "Not found pattern 'yyy' in text 'abc123xxx456'"
rgx("yyy").match("abc123xxx456").get() // throws "Not found pattern 'yyy' in text 'abc123xxx456'"
rgx("xxx(\\d+)").match("abc123xxx456").group(3) // "throws Match doesn't contain group: 3. Total groups are: 1"
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
RgxApi
public RgxApi()
-
-
Method Details
-
rgx
Usage example:rgx("\\d(\\d\\d)").match("abc123xxx456").group(1) // returns "123"- Parameters:
pattern- regular expression- Returns:
- Rgx wrapper
-
rgx
Use regex with flags
Usage example:rgx("ABC", Pattern.CASE_INSENSITIVE).match("abc123XXX456").get() // returns "abc" rgx("ABC.+DEF", CASE_INSENSITIVE | DOTALL).match("abc \n def").get() // returns "abc \n def"- Parameters:
pattern- regular expressionflags- Regex flags. Same as second argument in:Pattern.compile(String, int)- Returns:
- Rgx wrapper
-