Result
t
RESCRIPT
type t = array<option<string>>
Type representing the result of a RegExp
execution.
fullMatch
RESCRIPT
let fullMatch: t => string
fullMatch(regExpResult)
returns the full string that matched in this result.
Examples
RESCRIPT// Match the first two words separated by a space
let regexp = RegExp.fromString("(\\w+) (\\w+)")
switch regexp->RegExp.exec("ReScript is pretty cool, right?") {
| None => Console.log("Nope, no match...")
| Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is"
}
matches
RESCRIPT
let matches: t => array<string>
matches(regExpResult)
returns all matches for regExpResult
.
Examples
RESCRIPT// Match the first two words separated by a space
let regexp = RegExp.fromString("(\\w+) (\\w+)")
// This below will log "ReScript" and "is" to the console.
switch regexp->RegExp.exec("ReScript is pretty cool, right?") {
| None => Console.log("Nope, no match...")
| Some(result) => switch result->RegExp.Result.matches {
| [firstWord, secondWord] => Console.log2(firstWord, secondWord)
| _ => Console.log("Didn't find exactly two words...")
}
}
index
RESCRIPT
let index: t => int
input
RESCRIPT
let input: t => string
input(regExpResult)
returns the full input string that was passed to what produced the RegExp.Result.t
.
Examples
RESCRIPT// Match the first two words separated by a space
let regexp = RegExp.fromString("(\\w+) (\\w+)")
// This below will log the full input string "ReScript is pretty cool, right?" to the console.
switch regexp->RegExp.exec("ReScript is pretty cool, right?") {
| None => Console.log("Nope, no match...")
| Some(result) => Console.log(result->RegExp.Result.input)
}