Lynxer

Documentation

re

Regular expressions with familiar Python pattern syntax.

Backend: Rust — stdlib/re.so, built from rust/re over the shared rust/regex_engine (fancy-regex). Import: import("re") → global.re.*

Structured results (match lists, group lists, spans) are JSON strings.

FunctionSignatureReturns
test(str pattern, str string)true if the pattern matches anywhere
match(str pattern, str string)Match anchored at the start, or ""
matchFull(str pattern, str string)Full-string match, or ""
search(str pattern, str string)First match anywhere, or ""
findall(str pattern, str string)JSON array of all non-overlapping matches
count(str pattern, str string)Number of matches
groups(str pattern, str string)JSON array of capture groups of the first match
groupsAll(str pattern, str string)JSON array-of-arrays of groups per match
named(str pattern, str string)JSON object of named groups of the first match
sub(str pattern, str repl, str string)Replace every match
subN(str pattern, str repl, str string, int n)Replace the first n matches
subn(str pattern, str repl, str string)JSON {"result": ..., "count": N}
split(str pattern, str string)JSON array of the split parts
splitN(str pattern, str string, int maxSplit)Split at most maxSplit times
escape(str string)Regex-escaped literal text
matchStart(str pattern, str string)Byte start offset of the first match, or -1
matchEnd(str pattern, str string)Byte end offset of the first match, or -1
findSpans(str pattern, str string)JSON array of {start, end, match} with byte offsets
matchStartChar(str pattern, str string)Unicode scalar-value start index, or -1
matchEndChar(str pattern, str string)Unicode scalar-value end index, or -1
findSpansChar(str pattern, str string)The same span list with character indices
testIgnoreCase(str pattern, str string)test with the i flag
matchIgnoreCase(str pattern, str string)match with the i flag
searchIgnoreCase(str pattern, str string)search with the i flag
findallIgnoreCase(str pattern, str string)findall with the i flag
subIgnoreCase(str pattern, str repl, str string)sub with the i flag
findallMultiline(str pattern, str string)findall with the m flag
subMultiline(str pattern, str repl, str string)sub with the m flag
searchDotall(str pattern, str string)search with . matching newlines

Replacement strings support \1 and \g<name> backreferences.

Supported pattern syntax

The engine is a superset of ECMAScript, so Python/PCRE constructs work:

An invalid pattern is not an error: test is false, a string result is "" and an index is -1.

Byte-index helpers report UTF-8 byte offsets. The *Char variants count Unicode scalar values (not grapheme clusters); all indexes are zero-based and end indexes are exclusive.

Example

global setup(){ import("re"); }

global main(){
    println(global.re.findall("\\d+", "a1 b22 c333"));
    println(global.re.sub("(?P<w>\\w+)", "[\\g<w>]", "hi there"));
}

See also