Pattern

is a data type for pattern matching, similar to, but not the same as, Regular Expressions. See the docs for more information.

=

external

(Fn [(Ref Pattern a), (Ref Pattern b)] Bool)

MatchResult

module

Module

copy

external

(Fn [(Ref Pattern a)] Pattern)

delete

external

(Fn [Pattern] ())

extract

defn

(Fn [(Ref Pattern.MatchResult a), (Ref String b)] (Maybe String))

                        (extract match-res data)
                    

find

defn

(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

defn

(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

defn

(Fn [(Ref Pattern a), (Ref String b)] (Array Pattern.MatchResult))

                        (find-all-matches pattern data)
                    

from-chars

defn

(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

defn

(Fn [(Ref Pattern a), (Ref String b)] (Array String))

                        (global-match-str pattern data)
                    

init

external

(Fn [(Ref String a)] Pattern)

match

defn

(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

external

(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

external

(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

external

(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

defn

(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?

defn

(Fn [(Ref Pattern a), (Ref String b)] Bool)

                        (matches? pat s)
                    

checks whether a pattern matches a string.

non-match?

defn

(Fn [(Ref Pattern.MatchResult a)] Bool)

                        (non-match? match-res)
                    

prn

external

(Fn [(Ref Pattern a)] String)

split

defn

(Fn [(Ref Pattern a), (Ref String b)] (Array String))

                        (split p s)
                    

splits a string by a pattern.

str

external

(Fn [(Ref Pattern a)] String)

substitute

external

(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.