Regular Expression (Regex) Pattern Matching (JAD-I-438)
JADE now provides the JadeRegexLibrary class, which is the abstract superclass of the regular expression (Regex) pattern‑matching Application Programming Interface (API) subclasses in JADE. This API reduces hand‑crafted string parsing and code manipulation, to assist in the reading and testing of your code.
JADE does not implement a Regex engine itself, but wraps an existing implementation (the Per Compatible Regular Expressions (PCRE) library) with defined behavior and documentation. JADE Regex therefore uses the PCRE dialect, whose documentation that can be found at https://www.pcre.org/current/doc/html/pcre2syntax.html.
The JADE regular expression pattern‑matching provides:
-
The ability to find words and numbers, and their positions in a body of text based on a pattern
-
The ability to replace a word or number in a body of text based on a pattern with a substitute word or number
-
Extraction of data, using a pattern to extract data fields from a string
-
Validation of data; for example, checking that a credit card number is in the correct format
-
Command line Key=Value pair parsing
-
Log error message parsing, particularly in a test framework
The subclasses of the JadeRegexLibrary superclass are summarized in the following table. (For details, see
Class | Description |
---|---|
JadeRegex | Contains type methods for quick, simple use of the JadeRegexLibrary. Each method has common options that suit many use cases. |
JadeRegexCapture | A capture group of your regular expression, containing information about it; for example, the text it matched, the group name, length, and so on |
JadeRegexMatch | A single match of your regular expression against the subject string. It optionally contains JadeRegexCapture objects if capturing groups is enabled. |
JadeRegexPattern |
A compiled Regex object that provides enhanced functionality and performance over the JadeRegex class and its type methods. |
JadeRegexResult | An object representing one or more matches resulting from a Regex operation. |
In addition, the JadeRegexException subclass of the NormalException class is the transient class that defines details for exceptions that occur as a result of JADE regular expression pattern matching.