Pattern
is a data type for pattern matching, similar to, but not the same as, Regular Expressions. See the docs for more information.
extract
(Fn [(Ref Pattern.MatchResult a), (Ref String b)] (Maybe String))
(extract match-res data)
find
(Fn [(Ref Pattern a), (Ref String b)] Int)
(find pattern data)
finds the index of a pattern in a string.
Returns -1
if it doesn’t find a matching pattern.
find-all
(Fn [(Ref Pattern a), (Ref String b)] (Array Int))
(find-all pattern data)
finds all indices of a pattern in a string. The patterns may not overlap.
Returns []
if it doesn’t find a matching pattern.
find-all-matches
(Fn [(Ref Pattern a), (Ref String b)] (Array Pattern.MatchResult))
(find-all-matches pattern data)
from-chars
(Fn [(Ref (Array Char) a)] Pattern)
(from-chars chars)
creates a pattern that matches a group of characters from a list of those characters.
global-match-str
(Fn [(Ref Pattern a), (Ref String b)] (Array String))
(global-match-str pattern data)
match
(Fn [(Ref Pattern a), (Ref String b)] Pattern.MatchResult)
(match pattern data)
returns start and end indizes of the first match after the start of the string. Note that the end index points to the 1st character after the match (like all slice functions).
match-all-groups
(Fn [(Ref Pattern a), (Ref String b)] (Array (Array String)))
finds all match groups of a pattern in a string as a nested array.
Returns []
if it doesn’t find a matching pattern.
match-from
(Fn [(Ref Pattern a), (Ref String b), Int] Pattern.MatchResult)
returns start and end indizes of the first match after start-pos. Note that the end index points to the 1st character after the match (like all slice functions).
match-groups
(Fn [(Ref Pattern a), (Ref String b)] (Array String))
finds the match groups of the first match of a pattern in a string.
Returns []
if it doesn’t find a matching pattern.
match-str
(Fn [(Ref Pattern a), (Ref String b)] String)
(match-str pattern data)
finds the first match of a pattern in a string.
Returns an empty string if it doesn’t find a matching pattern.
matches?
(Fn [(Ref Pattern a), (Ref String b)] Bool)
(matches? pat s)
checks whether a pattern matches a string.
split
(Fn [(Ref Pattern a), (Ref String b)] (Array String))
(split p s)
splits a string by a pattern.
substitute
(Fn [(Ref Pattern a), (Ref String b), (Ref String c), Int] String)
finds all matches of a pattern in a string and replaces it
by another pattern n
times.
The substitute pattern can reference the original pattern by match group
indices, such as \1
. This means that backslashes need to be double escaped.
If you want to replace all occurrences of the pattern, use -1
.