Comment on page
Regular expressions
Functions for working with regular expressions are described here.
The FindFirstRegExp function finds the first occurrence of the regular expression re in the specified string src. The function returns an array of strings. The first element contains a substring that matches the regular expression, the remaining elements contain values of (...) groups, if they are defined in the regular expression.
arr.str a &= FindFirstRegExp(`This45i33s a isi777s inis1i2sg`, `is(\d*)i(\d+)s`)
// a = {`is45i33s`, `45`, `33`}
The FindRegExp function finds all occurrences of the re regular expression in the specified string src. The function returns an array of arrays. The first element in each array contains a substring that matches the regular expression.
arr.arr.str a &= FindRegExp(`My email is [email protected]`, `(\w+)@(\w+)\.(\w+)`)
// a = { { `[email protected]`, `xyz`, `example`, `com`} }
a &= FindRegExp(`This is a test string`, `i.`)
// a = { { `is` }, {`is`}, {`in`} }
The Match function reports whether the string s contains any match of the regular expression pattern re.
bool a = Match(`somethiabng striabnbg`, `a.b`) // false
a = Match(`somethianbg string`, `a.b`) // true
The RegExp function returns the first occurrence of the regular expression re in the specified line src. If no match is found, an empty string is returned.
str input = "This is a string тестовое значение"
ret = RegExp(input, `is (.{2})`) + RegExp(input, `е(.+?)е`)
// isстово
The FindRegExp function replaces matches of the re regular expression with the replacement string repl. You can specify $i or ${i} in repl* for i-the submatch.
str s = ReplaceRegExp("This is a string", `i(.{2})`, "xyz")
// Thxyzxyza strxyz
s = ReplaceRegExp(" email is [email protected]", `(\w+)@(\w+)\.(\w+)`, "${3}.${2}@zzz")
// email is com.example@zzz
Last modified 3yr ago