Package dev.comfast.rgx
Class Rgx
java.lang.Object
dev.comfast.rgx.Rgx
Provide fluent interface for common Regex operations. Most cases can be done in one line with proper error handling:
rgx("\\d+").match("abc123xxx456").get() -> returns "123"
rgx("\\d+").match("abc123xxx456").matchAllAsString() -> returns ["123", "456"]
rgx("xxx(\\d+)").match("abc123xxx456").group(1) -> returns "456"
rgx("yyy").match("abc123xxx456").isPresent() -> returns false;
Also throwing 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"
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
pattern
-
-
Constructor Details
-
Rgx
-
-
Method Details
-
flags
- Parameters:
flags- Regex flags. Same as second argument in: Pattern.compile(String, int)- See Also:
Pattern.compile(String, int)
-
match
- Returns:
- First match.
-
matchAllAsString
- Returns:
- All matches.
-
matchAllAsString
- Returns:
- Nth group from all matches.
-
matchAll
- Returns:
- All matches list.
-
toString
-