Regex
Basic support for regular expression matching on Strings.
This module uses the builtin Regex datatype representing a compiled regular expression and
alternative implementations of functions from String.flix using regular expressions.
Note - for regex matching all scanning is left-to-right and "chunked" by the matcher. This differs from String.flix where scanning is character at a time and can be left-to-right or right-to-left. Hence this module provides analogue but not exactly equivalent of functions: e.g.
String.indexOfLeft ~> Regex/Text.indexOfFirst String.indexOfRight ~> Regex/Text.indexOfLast String.breakOnLeft ~> Regex/Text.breakOnFirst String.breakOnRight ~> Regex/Text.breakOnLast
Type Aliases
Definitions
Find the first instance of Regex substr in string s, return a pair of the
prefix of string s up to and including sub and the rest of string s after sub.
Find the last instance of substr in string s, return a pair of the
initial string including substr and suffix from substr.
Find the first instance of Regex substr in string s, return a pair of the
prefix of string s up to sub and the rest of string s including sub.
Find the last instance of substr in string s, return a pair of the
initial string including substr and suffix from substr.
Returns the contents of the all the capture groups of substr in s.
Returns Nil if substr is the empty string or regex contains no groups.
Count the occurrences of substr in string s.
def countSubmatchesWithBounds(substr: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Int32§ SourceCount the occurrences of substr in string s within the bounds (start, end).
Returns 0 if the bounds are invalid.
Returns true if the string input ends the regular expression Regex suffix.
This will be slower than startsWith because there is no primitive Java function
to call, instead the matches of patt are iterated until the last one is found.
Return the content of the first occurence of substr in s from the left.
If the Regex substr is not present in s return None.
def getFirstWithBounds(substr: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Option[String]§ SourceReturn the content of the first occurence of substr in s from the left within
the bounds (start, end).
If the Regex substr is not present in s or the bounds are invalid return None.
This is getFirst with a start offset.
If the Regex substr is not present in s return None.
Return the content of the last occurence of substr in s from the left.
If the Regex substr is not present in s return None.
def getLastWithBounds(substr: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Option[String]§ SourceReturn the content of the last occurence of substr in s from the left within
the bounds (start, end).
If the Regex substr is not present in s or the bounds are invalid return None.
This is getLast with a start offset.
If the Regex substr is not present in s return None.
Returns Some(prefix) of string s if its prefix matches substr.
Returns Some(suffix) of string s if its suffix matches substr.
Return the index of the first occurence of substr in s from the left.
If the Regex substr is not present in s return None.
def indexOfFirstWithBounds(substr: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Option[Int32]§ SourceReturn the index of the first occurence of substr in s from the left within
the bounds (start, end).
If the Regex substr is not present in s or the bounds are invalid return None.
This is indexOfFirst with a start offset.
If the Regex substr is not present in s return None.
Return the index of the last occurence of substr in s starting from the left.
If the Regex substr is not present in s return None.
def indexOfLastWithBounds(substr: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Option[Int32]§ SourceReturn the index of the last occurence of substr in s from the left within
the bounds (start, end).
If the Regex substr is not present in s or the bounds are invalid return None.
This is indexOfLast with a start offset.
If the Regex substr is not present in s return None.
Returns the positions of the all the occurrences of substr in s.
If substr regexp matches the empty string, positions where an empty match
has been recognized will be returned.
def indicesOfWithBounds(substr: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Vector[Int32]§ SourceReturns the positions of the all the occurrences of substr in s
within the bounds (start, end).
If substr regexp matches the empty string, positions where an empty match
has been recognized will be returned.
Returns an empty vector if there are no matches or the bounds are invalid.
Returns true if the entire string s is matched by the Regex rgx.
def isMatchWithBounds(rgx: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Bool§ SourceReturns true if the entire string s is matched by the Regex rgx.
Returns false if the entire string does not match or the bounds are invalid.
Returns true if the string input is matched by the Regex rgx
at any position within the string s.
def isSubmatchWithBounds(rgx: Regex, start: { start = Int32 }, end: { end = Int32 }, s: String): Bool§ SourceReturns true if the string input is matched by the Regex rgx
at any position within the string s that is within the bounds (start, end).
Returns false if there is no match or the bounds are invalid.
Return the regular expression string used to build this Regex.
Return the regular expression string that matches the literal string s.
Returns string s with every match of the Regex src replaced by the string dst.
Returns string s with the first match of the regular expression src replaced by the string dst.
Splits the string s around matches of the Regex rgx.
Returns true if the string s starts the Regex prefix.
Returns Some(suffix) of string s if its prefix matches substr.
Returns Some(prefix) of string s if its suffix matches substr.
Returns the contents of the all the occurrences of substr in s.
Returns Nil if substr is the empty string.