Skip to content

Latest commit

 

History

History
132 lines (86 loc) · 2.89 KB

Regex.md

File metadata and controls

132 lines (86 loc) · 2.89 KB

Module Data.String.Regex

Wraps Javascript's RegExp object that enables matching strings with patternes defined by regular expressions. For details of the underlying implementation, see RegExp Reference at MDN.

Regex

data Regex :: *

Wraps Javascript RegExp objects.

Instances
instance showRegex :: Show Regex

RegexFlags

type RegexFlags = { global :: Boolean, ignoreCase :: Boolean, multiline :: Boolean, sticky :: Boolean, unicode :: Boolean }

Flags that control matching.

noFlags

noFlags :: RegexFlags

All flags set to false.

regex

regex :: String -> RegexFlags -> Regex

Constructs a Regex from a pattern string and flags.

source

source :: Regex -> String

Returns the pattern string used to construct the given Regex.

flags

flags :: Regex -> RegexFlags

Returns the RegexFlags used to construct the given Regex.

renderFlags

renderFlags :: RegexFlags -> String

Returns the string representation of the given RegexFlags.

parseFlags

parseFlags :: String -> RegexFlags

Parses the string representation of RegexFlags.

test

test :: Regex -> String -> Boolean

Returns true if the Regex matches the string.

match

match :: Regex -> String -> Maybe (Array (Maybe String))

Matches the string against the Regex and returns an array of matches if there were any. Each match has type Maybe String, where Nothing represents an unmatched optional capturing group. See reference.

replace

replace :: Regex -> String -> String -> String

Replaces occurences of the Regex with the first string. The replacement string can include special replacement patterns escaped with "$". See reference.

replace'

replace' :: Regex -> (String -> Array String -> String) -> String -> String

Transforms occurences of the Regex using a function of the matched substring and a list of submatch strings. See the reference.

search

search :: Regex -> String -> Maybe Int

Returns Just the index of the first match of the Regex in the string, or Nothing if there is no match.

split

split :: Regex -> String -> Array String

Split the string into an array of substrings along occurences of the Regex.