This is the clj-re Reference Manual, version 1.0.2, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 05:40:47 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
clj-re
Implements Clojure-styled regexp operations such as ‘re-matches‘ and ‘re-find‘.
Dave Tenny
MIT
1.0.2
cl-ppcre
(system).
named-readtables
(system).
package.lisp
(file).
clj-re.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
clj-re/clj-re.lisp
package.lisp
(file).
clj-re
(system).
re-find
(function).
re-groups
(function).
re-matcher
(function).
re-matches
(function).
re-pattern
(function).
re-quote-replacement
(function).
re-replace
(function).
re-replace-first
(function).
re-seq
(function).
re-split
(function).
clojure-replacement-translation
(function).
copy-matcher
(function).
make-matcher
(function).
matcher
(structure).
matcher-done?
(reader).
(setf matcher-done?)
(writer).
matcher-match-end
(reader).
(setf matcher-match-end)
(writer).
matcher-match-start
(reader).
(setf matcher-match-start)
(writer).
matcher-p
(function).
matcher-reg-ends
(reader).
(setf matcher-reg-ends)
(writer).
matcher-reg-starts
(reader).
(setf matcher-reg-starts)
(writer).
matcher-scanner
(reader).
(setf matcher-scanner)
(writer).
matcher-string
(reader).
(setf matcher-string)
(writer).
next
(function).
pattern
(type).
ppcre-replacement-quoter
(function).
re-replace-aux
(function).
regex-literal-reader
(function).
Packages are listed by definition order.
clj-re
Functions that implement Clojure style regexp operations.
cl-ppcre
.
common-lisp
.
re-find
(function).
re-groups
(function).
re-matcher
(function).
re-matches
(function).
re-pattern
(function).
re-quote-replacement
(function).
re-replace
(function).
re-replace-first
(function).
re-seq
(function).
re-split
(function).
clojure-replacement-translation
(function).
copy-matcher
(function).
make-matcher
(function).
matcher
(structure).
matcher-done?
(reader).
(setf matcher-done?)
(writer).
matcher-match-end
(reader).
(setf matcher-match-end)
(writer).
matcher-match-start
(reader).
(setf matcher-match-start)
(writer).
matcher-p
(function).
matcher-reg-ends
(reader).
(setf matcher-reg-ends)
(writer).
matcher-reg-starts
(reader).
(setf matcher-reg-starts)
(writer).
matcher-scanner
(reader).
(setf matcher-scanner)
(writer).
matcher-string
(reader).
(setf matcher-string)
(writer).
next
(function).
pattern
(type).
ppcre-replacement-quoter
(function).
re-replace-aux
(function).
regex-literal-reader
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Attempts to find the next subsequence of the input sequence that matches the pattern,
as per java.util.regex.Matcher.find(). Uses re-groups to return the groups.
Returns:
* If there no match, nil.
* If there is a match, but no groups, returns the match. E.g.
(re-find "a*b" "ab") => "ab"
* If there is a match groups are involved, returns a list whose car is the full match,
an whose remaining elements are the matched groups.
Call as ‘(re-find matcher)‘ or ‘(re-find regexp string)‘.
In the case where the first argument is not a matcher,
regexp may be a pattern or a string expression of a pattern.
Note that repeated calls to a matcher act like an iterator, while repeated calls with regexp and string arguments do not.
Returns the groups from the most recent call to ‘re-find‘ or ‘re-matches‘. If there are no
nested groups, returns a string of the entire match. If there are
nested groups, returns a list of the groups, the first element
being the entire match. Returns nil if there is no match indicated.
Returns a matcher for use in operations such as ‘re-groups‘ or ‘re-find‘.
Regexp may be a pattern, or a string expression of a pattern.
Attempts to match the _entire region_ of string against the regexp as per
java.util.regex.Matcher.matches(). Uses re-groups to return the
groups. Returns nil if the pattern doesn’t match the entire string.
Regexp may be a pattern, or a string expressing a pattern.
In Clojure: Returns an instance of java.util.regex.Pattern, for use, e.g. in re-matcher.
In Common Lisp: returns a compiled pattern (cl-ppcre scanner).
Note that clojure (and this module) allow ’s’ to be a pattern as well as a string
expressing a pattern.
In clojure this would be ‘clojure.string/re-quote-replacement‘.
Given a replacement string that you wish to be a literal
replacement for a pattern match in ‘re-replace‘ or ‘re-replace-first‘, do the
necessary escaping of special characters in the replacement.
In clojure this would be ‘clojure.string/replace‘.
Replaces all instances of ’match’ with ’replacement’ in ’string’.
If there are no matches, the input ’string’ value is returned.
Note that if you want more power, use ‘cl-ppcre:regex-replace[-all]‘ instead, but that
it has different replacement directives which are disabled for clojure compatability.
‘match‘ / ‘replacement‘ can be:
string / string
char / char
pattern / (string or function of match).
See also ‘re-replace-first‘.
If replacement is a function it should take one argument (the match to be replaced) and return the replacement value. Note that the argument could be a list if the pattern contains capturing groups (as per ‘re-groups‘), i.e. ‘(match, register1, register2, ...)‘.
The ‘replacement‘ is literal (i.e. none of its characters are treated
specially) for all cases above except pattern / string.
CAUTION: This behavior is different from most regexp functions in this package that
interpret strings as patterns. A string as the ’match’ argument is treated literally and
not as an expression of a pattern. This is for conformance with clojure’s behavior.
For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern. If you wish your replacement
string ’r’ to be used literally, use ‘(re-quote-replacement r)‘ as the
replacement argument.
Example:
‘(/re-replace "Almost Pig Latin" "\b(\w)(\w+)\b" "$2$1ay")
-> "lmostAay igPay atinLay"
In clojure this would be ‘clojure.string/replace-first‘.
Replaces the _first_ instance of ’match’ with ’replacement’ in ’string’.
See ‘re-replace‘ for argument syntax and semantics.
CAUTION: unlike many of the re-* functions, this function will take a string
‘match‘ argument as a literal text match, not a pattern.
Be sure to pass a pattern if you want pattern matching, as with
‘(re-pattern <string>)‘.
Returns a list of successive matches of regexp in string as by using java.util.regex.Matcher.find(), each such match processed with re-groups.
Regexp may be a pattern or string expression of a pattern.
Note that the clojure version would return a lazy sequence, but we don’t have those and so the result is not lazy.
In clojure this would be clojure.string/split.
Splits string on a regular expression, which may be a pattern or a string
expression of a pattern. Optional argument limit is the maximum number of
splits. Returns list of the splits.
Resulting strings do not share structure with the input.
Note that capture groups (cl-ppcre registers) have no effect on the operation except perhaps to make it perform more slowly
Translate clojure-style replacement operations, e.g. $1, into cl-ppcre replacement operations e.g. \1. Do NOT do the translations if the replacement string has ben quoted by the user via re-quote-replacement. Presently assumes repalcement-string has NOT been quoted with cl-ppcre:quote-meta-chars, but more selectively quoted just to ’literalize’ cl-ppcre replacement directives like N.
Find the next match, return nil if there aren’t any T if there are, in which case the matcher values are updated.
Given a string which may contain replacement directives for cl-pprcre:replace[-all] quote them, since they have no meaning under clojure replacement syntax and/or semantics. The directives we’re looking for are: N or {N} (for some digit), &, ‘, ’
Does the work of re-replace and re-replace-first.
The logic is identical between the two except for which cl-ppcre function is called,
as specified by the last argument.
Reads a string as a regex literal and returns a compiled pattern.
E.g. Instead of "\\d+" you can specify #"\d+", with the added benefit
of a returned ’compiled’ regular expression in the form of a cl-ppcre scanner.
The main difference with respect to string char interpretation is that
the backslash is always read into the resulting string, whereas lisp would discard
the first such backslash, allowing backslashes into the result only if double-backslash
were found.
Like the lisp string reader, the character following the backslash
is effectively escaped, and will always be a part of the string. So you can use
backslash-quote to escape a quote that would otherwise teriminate the string.
Emulate java Matcher binding to a string to be scanned.
structure-object
.
common-lisp
.
string
""
integer
0
integer
0
(array (or null integer))
#()
(array (or null integer))
#()
Alias for a compiled regexp emulating a java Pattern, in our case a cl-ppcre ’scanner’.
Jump to: | (
C F M N P R |
---|
Jump to: | (
C F M N P R |
---|
Jump to: | D M R S |
---|
Jump to: | D M R S |
---|
Jump to: | C F M P S T |
---|
Jump to: | C F M P S T |
---|