regex
import regexFunctions
Section titled “Functions”| Function | Signature | Description |
|---|---|---|
is_match | (String, String) -> Bool | Check if a pattern matches anywhere in a string. |
full_match | (String, String) -> Bool | Check if a pattern matches the entire string. |
find | (String, String) -> Option[String] | Find the first match of a pattern in a string. |
find_all | (String, String) -> List[String] | Find all non-overlapping matches of a pattern. |
replace | (String, String, String) -> String | Replace all matches of a pattern with a replacement string. |
replace_first | (String, String, String) -> String | Replace the first match of a pattern. |
split | (String, String) -> List[String] | Split a string by a regex pattern. |
captures | (String, String) -> Option[List[String]] | Extract capture groups from the first match. |
Reference
Section titled “Reference”regex.is_match(pat: String, s: String) -> Bool
Section titled “regex.is_match(pat: String, s: String) -> Bool”Check if a pattern matches anywhere in a string.
regex.is_match("[0-9]+", "abc123") // => trueregex.full_match(pat: String, s: String) -> Bool
Section titled “regex.full_match(pat: String, s: String) -> Bool”Check if a pattern matches the entire string.
regex.full_match("[0-9]+", "123") // => trueregex.find(pat: String, s: String) -> Option[String]
Section titled “regex.find(pat: String, s: String) -> Option[String]”Find the first match of a pattern in a string.
regex.find("[0-9]+", "abc123def") // => some("123")regex.find_all(pat: String, s: String) -> List[String]
Section titled “regex.find_all(pat: String, s: String) -> List[String]”Find all non-overlapping matches of a pattern.
regex.find_all("[0-9]+", "a1b2c3") // => ["1", "2", "3"]regex.replace(pat: String, s: String, rep: String) -> String
Section titled “regex.replace(pat: String, s: String, rep: String) -> String”Replace all matches of a pattern with a replacement string.
regex.replace("[0-9]+", "a1b2", "X") // => "aXbX"regex.replace_first(pat: String, s: String, rep: String) -> String
Section titled “regex.replace_first(pat: String, s: String, rep: String) -> String”Replace the first match of a pattern.
regex.replace_first("[0-9]+", "a1b2", "X") // => "aXb2"regex.split(pat: String, s: String) -> List[String]
Section titled “regex.split(pat: String, s: String) -> List[String]”Split a string by a regex pattern.
regex.split("[,;]", "a,b;c") // => ["a", "b", "c"]regex.captures(pat: String, s: String) -> Option[List[String]]
Section titled “regex.captures(pat: String, s: String) -> Option[List[String]]”Extract capture groups from the first match.
regex.captures("(\\w+)@(\\w+)", "user@host") // => some(["user@host", "user", "host"])