rencg.api
The public API of rencg.
re-find
multimethod
(re-find m)(re-find m ncgs)(re-find re s)(re-find re s ncgs)Equivalent to clojure.core/re-find, but returns the result of calling re-groups when the pattern is found, or nil otherwise.
If multiple finds are being performed, the versions where the sequence of named-capturing groups is passed in may be more efficient as they allow the caller to determine the named-capturing groups in the regex once (e.g. using re-named-groups), then reuse that information, potentially avoiding re-parsing of the regex on each call.
re-groups
(re-groups m)(re-groups m ncgs)Equivalent to clojure.core/re-groups, but instead of returning a sequence containing the entire match and each group, it returns a map of the named-capturing groups as well as the start index (:start), end index (:end), and text (:match) of the entire match.
The key for each named-capturing group that’s found is the (String) name of that group, and the corresponding value is the (String) text that matched that group.
If the same regex is being used many times, the 2-arg version may be more efficient as it allows the caller to determine the named-capturing groups in the regex once (e.g. using re-named-groups), then reuse that information, potentially avoiding re-parsing of the regex on each call.
re-matches
(re-matches re s)(re-matches re s ncgs)Equivalent to clojure.core/re-matches, but returns the result of calling re-groups when there’s a match, or nil otherwise.
If the regex is being reused many times, the 3-arg version may be more efficient as it allows the caller to determine the named-capturing groups in the regex once (e.g. using re-named-groups), then reuse that information, potentially avoiding re-parsing of the regex on each call.
re-named-groups
multimethod
(re-named-groups re)(re-named-groups m)Returns the names of all of the named-capturing groups in the given regular expression (java.util.regex.Pattern) or matcher (java.util.regex.Matcher) as a set of Strings, or an empty set if there aren’t any. Returns nil if the argument is nil.
Note: on older JDKs (pre v20), this uses a JDK-agnostic workaround for JDK-7032377.
re-seq
(re-seq re s)(re-seq re s ncgs)Equivalent to clojure.core/re-seq, but returns the result of calling re-groups on each successive match, or nil if there are no matches.
If the regex is being reused many times, the 3-arg version may be more efficient as it allows the caller to determine the named-capturing groups in the regex once (e.g. using re-named-groups), then reuse that information, potentially avoiding re-parsing of the regex on each call.