τau /

regexp

module
regexp = import("regexp")

regexp - regular expressions, in the shape of Go's regexp package.

The pattern is parsed into a tree, compiled into a small program and run by a Pike VM: a Thompson NFA simulation carrying the capture slots along. Every thread advances one character at a time and there is at most one thread per instruction, so matching takes O(len(text) * len(program)) whatever the pattern, with none of the exponential blowups of a backtracking engine.

Supported syntax:

.            any character, a newline too under the s flag
[abc]        class, with ranges and negation as [^a-z]
[[:alpha:]]  POSIX class, [[:^alpha:]] to negate it
\d \w \s     digit, word and space classes, uppercase to negate
\b \B        word boundary
^ $          beginning and end of the text, of the line under m
\A \z        beginning and end of the text, whatever the flags
x* x+ x?     repetition, append ? for the lazy form
x{n,m}       counted repetition, {n} and {n,} too
(x)          capturing group, (?:x) plain group
(?P<n>x)     named group, (?<n>x) spells the same thing
(?i) (?i:x)  flags, i m s U, until the group ends or for x alone
\Q...\E      literal text, whatever punctuation it holds
\n \x7f \177 escapes, by name, by hexadecimal, by octal
a|b          alternation

The text is walked one byte at a time, so a pattern speaks of bytes and not of runes: . matches a byte and a range like [α-ω] means nothing.

Compile = fn(pattern)source

Compile parses a pattern and returns a Regexp, or an error.

String = fn()source

NumSubexp = fn()source

NumSubexp returns the number of capturing groups.

SubexpNames = fn()source

SubexpNames returns the name of every group, empty for the ones that were never given one. The first entry stands for the whole match and is always empty, so that a name sits at the index of its group.

SubexpIndex = fn(name)source

SubexpIndex returns the number of the group called name, or -1.

Copy = fn()source

Copy returns a Regexp that matches the same pattern, so that a Longest said on the one leaves the other one alone.

MarshalText = fn()source

MarshalText writes the Regexp out as the pattern it was compiled from.

UnmarshalText = fn(b)source

UnmarshalText makes the Regexp the one that the given pattern spells.

Longest = fn()source

Longest asks the searches that follow for the leftmost longest match instead of the leftmost first one, as POSIX wants it. It changes the regexp itself, so say it before searching and not in the middle.

LiteralPrefix = fn()source

LiteralPrefix returns [prefix, complete]: the text every match must begin with, and whether the pattern is that text and nothing else.

FindStringSubmatchIndex = fn(s)source

FindStringSubmatchIndex returns the index pairs of the leftmost match and of its groups, null when there is no match.

FindStringIndex = fn(s)source

FindStringIndex returns the start and the end of the leftmost match.

FindString = fn(s)source

FindString returns the text of the leftmost match, empty if there is none.

FindStringSubmatch = fn(s)source

FindStringSubmatch returns the match and its groups. A group that took no part in the match is null.

MatchString = fn(s)source

MatchString reports whether s contains a match.

Match = fn(b)source

FindReaderSubmatchIndex = fn(r)source

The reader side of the family. Go reads only as far as it must, this reads the stream to its end and searches what it read.

ponytail: an endless reader would never return here, which no stream a file or a connection gives ever is. Searching as the bytes come in is what to write the day one is.

FindReaderIndex = fn(r)source

MatchReader = fn(r)source

FindAllString = fn(s, n)source

FindAllString returns up to n matches, all of them when n is -1.

FindAllStringIndex = fn(s, n)source

FindAllStringSubmatch = fn(s, n)source

FindAllStringSubmatchIndex = fn(s, n)source

Find = fn(b)source

FindIndex = fn(b)source

FindSubmatch = fn(b)source

FindSubmatchIndex = fn(b)source

FindAll = fn(b, n)source

FindAllIndex = fn(b, n)source

FindAllSubmatchIndex = fn(b, n)source

FindAllSubmatch = fn(b, n)source

ExpandString = fn(dst, template, s, match)source

ExpandString appends to dst the template with every $1 and ${name} of it put for what that group of match captured in s.

Expand = fn(dst, template, src, match)source

ReplaceAllStringFunc = fn(s, f)source

ReplaceAllStringFunc replaces every match with what f returns for it.

ReplaceAllString = fn(s, repl)source

ReplaceAllString replaces every match with repl, in which $1 and ${name} stand for what the groups captured.

ReplaceAllLiteralString = fn(s, repl)source

ReplaceAllLiteralString replaces every match with repl taken word for word, no dollar of it meaning anything.

ReplaceAll = fn(b, repl)source

ReplaceAllLiteral = fn(b, repl)source

ReplaceAllFunc = fn(b, f)source

Split = fn(s, n)source

Split slices s around every match, into at most n pieces when n >= 0.

CompilePOSIX = fn(pattern)source

CompilePOSIX is Compile for a plain POSIX ERE: none of the escapes and the groups Perl added, and the leftmost longest match instead of the first one.

String = fn()source

NumSubexp = fn()source

NumSubexp returns the number of capturing groups.

SubexpNames = fn()source

SubexpNames returns the name of every group, empty for the ones that were never given one. The first entry stands for the whole match and is always empty, so that a name sits at the index of its group.

SubexpIndex = fn(name)source

SubexpIndex returns the number of the group called name, or -1.

Copy = fn()source

Copy returns a Regexp that matches the same pattern, so that a Longest said on the one leaves the other one alone.

MarshalText = fn()source

MarshalText writes the Regexp out as the pattern it was compiled from.

UnmarshalText = fn(b)source

UnmarshalText makes the Regexp the one that the given pattern spells.

Longest = fn()source

Longest asks the searches that follow for the leftmost longest match instead of the leftmost first one, as POSIX wants it. It changes the regexp itself, so say it before searching and not in the middle.

LiteralPrefix = fn()source

LiteralPrefix returns [prefix, complete]: the text every match must begin with, and whether the pattern is that text and nothing else.

FindStringSubmatchIndex = fn(s)source

FindStringSubmatchIndex returns the index pairs of the leftmost match and of its groups, null when there is no match.

FindStringIndex = fn(s)source

FindStringIndex returns the start and the end of the leftmost match.

FindString = fn(s)source

FindString returns the text of the leftmost match, empty if there is none.

FindStringSubmatch = fn(s)source

FindStringSubmatch returns the match and its groups. A group that took no part in the match is null.

MatchString = fn(s)source

MatchString reports whether s contains a match.

Match = fn(b)source

FindReaderSubmatchIndex = fn(r)source

The reader side of the family. Go reads only as far as it must, this reads the stream to its end and searches what it read.

ponytail: an endless reader would never return here, which no stream a file or a connection gives ever is. Searching as the bytes come in is what to write the day one is.

FindReaderIndex = fn(r)source

MatchReader = fn(r)source

FindAllString = fn(s, n)source

FindAllString returns up to n matches, all of them when n is -1.

FindAllStringIndex = fn(s, n)source

FindAllStringSubmatch = fn(s, n)source

FindAllStringSubmatchIndex = fn(s, n)source

Find = fn(b)source

FindIndex = fn(b)source

FindSubmatch = fn(b)source

FindSubmatchIndex = fn(b)source

FindAll = fn(b, n)source

FindAllIndex = fn(b, n)source

FindAllSubmatchIndex = fn(b, n)source

FindAllSubmatch = fn(b, n)source

ExpandString = fn(dst, template, s, match)source

ExpandString appends to dst the template with every $1 and ${name} of it put for what that group of match captured in s.

Expand = fn(dst, template, src, match)source

ReplaceAllStringFunc = fn(s, f)source

ReplaceAllStringFunc replaces every match with what f returns for it.

ReplaceAllString = fn(s, repl)source

ReplaceAllString replaces every match with repl, in which $1 and ${name} stand for what the groups captured.

ReplaceAllLiteralString = fn(s, repl)source

ReplaceAllLiteralString replaces every match with repl taken word for word, no dollar of it meaning anything.

ReplaceAll = fn(b, repl)source

ReplaceAllLiteral = fn(b, repl)source

ReplaceAllFunc = fn(b, f)source

Split = fn(s, n)source

Split slices s around every match, into at most n pieces when n >= 0.

MustCompile = fn(pattern)source

MustCompile is Compile, but it stops the program on an invalid pattern.

String = fn()source

NumSubexp = fn()source

NumSubexp returns the number of capturing groups.

SubexpNames = fn()source

SubexpNames returns the name of every group, empty for the ones that were never given one. The first entry stands for the whole match and is always empty, so that a name sits at the index of its group.

SubexpIndex = fn(name)source

SubexpIndex returns the number of the group called name, or -1.

Copy = fn()source

Copy returns a Regexp that matches the same pattern, so that a Longest said on the one leaves the other one alone.

MarshalText = fn()source

MarshalText writes the Regexp out as the pattern it was compiled from.

UnmarshalText = fn(b)source

UnmarshalText makes the Regexp the one that the given pattern spells.

Longest = fn()source

Longest asks the searches that follow for the leftmost longest match instead of the leftmost first one, as POSIX wants it. It changes the regexp itself, so say it before searching and not in the middle.

LiteralPrefix = fn()source

LiteralPrefix returns [prefix, complete]: the text every match must begin with, and whether the pattern is that text and nothing else.

FindStringSubmatchIndex = fn(s)source

FindStringSubmatchIndex returns the index pairs of the leftmost match and of its groups, null when there is no match.

FindStringIndex = fn(s)source

FindStringIndex returns the start and the end of the leftmost match.

FindString = fn(s)source

FindString returns the text of the leftmost match, empty if there is none.

FindStringSubmatch = fn(s)source

FindStringSubmatch returns the match and its groups. A group that took no part in the match is null.

MatchString = fn(s)source

MatchString reports whether s contains a match.

Match = fn(b)source

FindReaderSubmatchIndex = fn(r)source

The reader side of the family. Go reads only as far as it must, this reads the stream to its end and searches what it read.

ponytail: an endless reader would never return here, which no stream a file or a connection gives ever is. Searching as the bytes come in is what to write the day one is.

FindReaderIndex = fn(r)source

MatchReader = fn(r)source

FindAllString = fn(s, n)source

FindAllString returns up to n matches, all of them when n is -1.

FindAllStringIndex = fn(s, n)source

FindAllStringSubmatch = fn(s, n)source

FindAllStringSubmatchIndex = fn(s, n)source

Find = fn(b)source

FindIndex = fn(b)source

FindSubmatch = fn(b)source

FindSubmatchIndex = fn(b)source

FindAll = fn(b, n)source

FindAllIndex = fn(b, n)source

FindAllSubmatchIndex = fn(b, n)source

FindAllSubmatch = fn(b, n)source

ExpandString = fn(dst, template, s, match)source

ExpandString appends to dst the template with every $1 and ${name} of it put for what that group of match captured in s.

Expand = fn(dst, template, src, match)source

ReplaceAllStringFunc = fn(s, f)source

ReplaceAllStringFunc replaces every match with what f returns for it.

ReplaceAllString = fn(s, repl)source

ReplaceAllString replaces every match with repl, in which $1 and ${name} stand for what the groups captured.

ReplaceAllLiteralString = fn(s, repl)source

ReplaceAllLiteralString replaces every match with repl taken word for word, no dollar of it meaning anything.

ReplaceAll = fn(b, repl)source

ReplaceAllLiteral = fn(b, repl)source

ReplaceAllFunc = fn(b, f)source

Split = fn(s, n)source

Split slices s around every match, into at most n pieces when n >= 0.

MustCompilePOSIX = fn(pattern)source

MustCompilePOSIX is CompilePOSIX, but it stops the program on an invalid pattern.

String = fn()source

NumSubexp = fn()source

NumSubexp returns the number of capturing groups.

SubexpNames = fn()source

SubexpNames returns the name of every group, empty for the ones that were never given one. The first entry stands for the whole match and is always empty, so that a name sits at the index of its group.

SubexpIndex = fn(name)source

SubexpIndex returns the number of the group called name, or -1.

Copy = fn()source

Copy returns a Regexp that matches the same pattern, so that a Longest said on the one leaves the other one alone.

MarshalText = fn()source

MarshalText writes the Regexp out as the pattern it was compiled from.

UnmarshalText = fn(b)source

UnmarshalText makes the Regexp the one that the given pattern spells.

Longest = fn()source

Longest asks the searches that follow for the leftmost longest match instead of the leftmost first one, as POSIX wants it. It changes the regexp itself, so say it before searching and not in the middle.

LiteralPrefix = fn()source

LiteralPrefix returns [prefix, complete]: the text every match must begin with, and whether the pattern is that text and nothing else.

FindStringSubmatchIndex = fn(s)source

FindStringSubmatchIndex returns the index pairs of the leftmost match and of its groups, null when there is no match.

FindStringIndex = fn(s)source

FindStringIndex returns the start and the end of the leftmost match.

FindString = fn(s)source

FindString returns the text of the leftmost match, empty if there is none.

FindStringSubmatch = fn(s)source

FindStringSubmatch returns the match and its groups. A group that took no part in the match is null.

MatchString = fn(s)source

MatchString reports whether s contains a match.

Match = fn(b)source

FindReaderSubmatchIndex = fn(r)source

The reader side of the family. Go reads only as far as it must, this reads the stream to its end and searches what it read.

ponytail: an endless reader would never return here, which no stream a file or a connection gives ever is. Searching as the bytes come in is what to write the day one is.

FindReaderIndex = fn(r)source

MatchReader = fn(r)source

FindAllString = fn(s, n)source

FindAllString returns up to n matches, all of them when n is -1.

FindAllStringIndex = fn(s, n)source

FindAllStringSubmatch = fn(s, n)source

FindAllStringSubmatchIndex = fn(s, n)source

Find = fn(b)source

FindIndex = fn(b)source

FindSubmatch = fn(b)source

FindSubmatchIndex = fn(b)source

FindAll = fn(b, n)source

FindAllIndex = fn(b, n)source

FindAllSubmatchIndex = fn(b, n)source

FindAllSubmatch = fn(b, n)source

ExpandString = fn(dst, template, s, match)source

ExpandString appends to dst the template with every $1 and ${name} of it put for what that group of match captured in s.

Expand = fn(dst, template, src, match)source

ReplaceAllStringFunc = fn(s, f)source

ReplaceAllStringFunc replaces every match with what f returns for it.

ReplaceAllString = fn(s, repl)source

ReplaceAllString replaces every match with repl, in which $1 and ${name} stand for what the groups captured.

ReplaceAllLiteralString = fn(s, repl)source

ReplaceAllLiteralString replaces every match with repl taken word for word, no dollar of it meaning anything.

ReplaceAll = fn(b, repl)source

ReplaceAllLiteral = fn(b, repl)source

ReplaceAllFunc = fn(b, f)source

Split = fn(s, n)source

Split slices s around every match, into at most n pieces when n >= 0.

QuoteMeta = fn(s)source

QuoteMeta returns a pattern that matches the literal text of s.

MatchString = fn(pattern, s)source

String = fn()source

NumSubexp = fn()source

NumSubexp returns the number of capturing groups.

SubexpNames = fn()source

SubexpNames returns the name of every group, empty for the ones that were never given one. The first entry stands for the whole match and is always empty, so that a name sits at the index of its group.

SubexpIndex = fn(name)source

SubexpIndex returns the number of the group called name, or -1.

Copy = fn()source

Copy returns a Regexp that matches the same pattern, so that a Longest said on the one leaves the other one alone.

MarshalText = fn()source

MarshalText writes the Regexp out as the pattern it was compiled from.

UnmarshalText = fn(b)source

UnmarshalText makes the Regexp the one that the given pattern spells.

Longest = fn()source

Longest asks the searches that follow for the leftmost longest match instead of the leftmost first one, as POSIX wants it. It changes the regexp itself, so say it before searching and not in the middle.

LiteralPrefix = fn()source

LiteralPrefix returns [prefix, complete]: the text every match must begin with, and whether the pattern is that text and nothing else.

FindStringSubmatchIndex = fn(s)source

FindStringSubmatchIndex returns the index pairs of the leftmost match and of its groups, null when there is no match.

FindStringIndex = fn(s)source

FindStringIndex returns the start and the end of the leftmost match.

FindString = fn(s)source

FindString returns the text of the leftmost match, empty if there is none.

FindStringSubmatch = fn(s)source

FindStringSubmatch returns the match and its groups. A group that took no part in the match is null.

MatchString = fn(s)source

MatchString reports whether s contains a match.

Match = fn(b)source

FindReaderSubmatchIndex = fn(r)source

The reader side of the family. Go reads only as far as it must, this reads the stream to its end and searches what it read.

ponytail: an endless reader would never return here, which no stream a file or a connection gives ever is. Searching as the bytes come in is what to write the day one is.

FindReaderIndex = fn(r)source

MatchReader = fn(r)source

FindAllString = fn(s, n)source

FindAllString returns up to n matches, all of them when n is -1.

FindAllStringIndex = fn(s, n)source

FindAllStringSubmatch = fn(s, n)source

FindAllStringSubmatchIndex = fn(s, n)source

Find = fn(b)source

FindIndex = fn(b)source

FindSubmatch = fn(b)source

FindSubmatchIndex = fn(b)source

FindAll = fn(b, n)source

FindAllIndex = fn(b, n)source

FindAllSubmatchIndex = fn(b, n)source

FindAllSubmatch = fn(b, n)source

ExpandString = fn(dst, template, s, match)source

ExpandString appends to dst the template with every $1 and ${name} of it put for what that group of match captured in s.

Expand = fn(dst, template, src, match)source

ReplaceAllStringFunc = fn(s, f)source

ReplaceAllStringFunc replaces every match with what f returns for it.

ReplaceAllString = fn(s, repl)source

ReplaceAllString replaces every match with repl, in which $1 and ${name} stand for what the groups captured.

ReplaceAllLiteralString = fn(s, repl)source

ReplaceAllLiteralString replaces every match with repl taken word for word, no dollar of it meaning anything.

ReplaceAll = fn(b, repl)source

ReplaceAllLiteral = fn(b, repl)source

ReplaceAllFunc = fn(b, f)source

Split = fn(s, n)source

Split slices s around every match, into at most n pieces when n >= 0.

Match = fn(pattern, b)source

String = fn()source

NumSubexp = fn()source

NumSubexp returns the number of capturing groups.

SubexpNames = fn()source

SubexpNames returns the name of every group, empty for the ones that were never given one. The first entry stands for the whole match and is always empty, so that a name sits at the index of its group.

SubexpIndex = fn(name)source

SubexpIndex returns the number of the group called name, or -1.

Copy = fn()source

Copy returns a Regexp that matches the same pattern, so that a Longest said on the one leaves the other one alone.

MarshalText = fn()source

MarshalText writes the Regexp out as the pattern it was compiled from.

UnmarshalText = fn(b)source

UnmarshalText makes the Regexp the one that the given pattern spells.

Longest = fn()source

Longest asks the searches that follow for the leftmost longest match instead of the leftmost first one, as POSIX wants it. It changes the regexp itself, so say it before searching and not in the middle.

LiteralPrefix = fn()source

LiteralPrefix returns [prefix, complete]: the text every match must begin with, and whether the pattern is that text and nothing else.

FindStringSubmatchIndex = fn(s)source

FindStringSubmatchIndex returns the index pairs of the leftmost match and of its groups, null when there is no match.

FindStringIndex = fn(s)source

FindStringIndex returns the start and the end of the leftmost match.

FindString = fn(s)source

FindString returns the text of the leftmost match, empty if there is none.

FindStringSubmatch = fn(s)source

FindStringSubmatch returns the match and its groups. A group that took no part in the match is null.

MatchString = fn(s)source

MatchString reports whether s contains a match.

Match = fn(b)source

FindReaderSubmatchIndex = fn(r)source

The reader side of the family. Go reads only as far as it must, this reads the stream to its end and searches what it read.

ponytail: an endless reader would never return here, which no stream a file or a connection gives ever is. Searching as the bytes come in is what to write the day one is.

FindReaderIndex = fn(r)source

MatchReader = fn(r)source

FindAllString = fn(s, n)source

FindAllString returns up to n matches, all of them when n is -1.

FindAllStringIndex = fn(s, n)source

FindAllStringSubmatch = fn(s, n)source

FindAllStringSubmatchIndex = fn(s, n)source

Find = fn(b)source

FindIndex = fn(b)source

FindSubmatch = fn(b)source

FindSubmatchIndex = fn(b)source

FindAll = fn(b, n)source

FindAllIndex = fn(b, n)source

FindAllSubmatchIndex = fn(b, n)source

FindAllSubmatch = fn(b, n)source

ExpandString = fn(dst, template, s, match)source

ExpandString appends to dst the template with every $1 and ${name} of it put for what that group of match captured in s.

Expand = fn(dst, template, src, match)source

ReplaceAllStringFunc = fn(s, f)source

ReplaceAllStringFunc replaces every match with what f returns for it.

ReplaceAllString = fn(s, repl)source

ReplaceAllString replaces every match with repl, in which $1 and ${name} stand for what the groups captured.

ReplaceAllLiteralString = fn(s, repl)source

ReplaceAllLiteralString replaces every match with repl taken word for word, no dollar of it meaning anything.

ReplaceAll = fn(b, repl)source

ReplaceAllLiteral = fn(b, repl)source

ReplaceAllFunc = fn(b, f)source

Split = fn(s, n)source

Split slices s around every match, into at most n pieces when n >= 0.

MatchReader = fn(pattern, r)source

String = fn()source

NumSubexp = fn()source

NumSubexp returns the number of capturing groups.

SubexpNames = fn()source

SubexpNames returns the name of every group, empty for the ones that were never given one. The first entry stands for the whole match and is always empty, so that a name sits at the index of its group.

SubexpIndex = fn(name)source

SubexpIndex returns the number of the group called name, or -1.

Copy = fn()source

Copy returns a Regexp that matches the same pattern, so that a Longest said on the one leaves the other one alone.

MarshalText = fn()source

MarshalText writes the Regexp out as the pattern it was compiled from.

UnmarshalText = fn(b)source

UnmarshalText makes the Regexp the one that the given pattern spells.

Longest = fn()source

Longest asks the searches that follow for the leftmost longest match instead of the leftmost first one, as POSIX wants it. It changes the regexp itself, so say it before searching and not in the middle.

LiteralPrefix = fn()source

LiteralPrefix returns [prefix, complete]: the text every match must begin with, and whether the pattern is that text and nothing else.

FindStringSubmatchIndex = fn(s)source

FindStringSubmatchIndex returns the index pairs of the leftmost match and of its groups, null when there is no match.

FindStringIndex = fn(s)source

FindStringIndex returns the start and the end of the leftmost match.

FindString = fn(s)source

FindString returns the text of the leftmost match, empty if there is none.

FindStringSubmatch = fn(s)source

FindStringSubmatch returns the match and its groups. A group that took no part in the match is null.

MatchString = fn(s)source

MatchString reports whether s contains a match.

Match = fn(b)source

FindReaderSubmatchIndex = fn(r)source

The reader side of the family. Go reads only as far as it must, this reads the stream to its end and searches what it read.

ponytail: an endless reader would never return here, which no stream a file or a connection gives ever is. Searching as the bytes come in is what to write the day one is.

FindReaderIndex = fn(r)source

MatchReader = fn(r)source

FindAllString = fn(s, n)source

FindAllString returns up to n matches, all of them when n is -1.

FindAllStringIndex = fn(s, n)source

FindAllStringSubmatch = fn(s, n)source

FindAllStringSubmatchIndex = fn(s, n)source

Find = fn(b)source

FindIndex = fn(b)source

FindSubmatch = fn(b)source

FindSubmatchIndex = fn(b)source

FindAll = fn(b, n)source

FindAllIndex = fn(b, n)source

FindAllSubmatchIndex = fn(b, n)source

FindAllSubmatch = fn(b, n)source

ExpandString = fn(dst, template, s, match)source

ExpandString appends to dst the template with every $1 and ${name} of it put for what that group of match captured in s.

Expand = fn(dst, template, src, match)source

ReplaceAllStringFunc = fn(s, f)source

ReplaceAllStringFunc replaces every match with what f returns for it.

ReplaceAllString = fn(s, repl)source

ReplaceAllString replaces every match with repl, in which $1 and ${name} stand for what the groups captured.

ReplaceAllLiteralString = fn(s, repl)source

ReplaceAllLiteralString replaces every match with repl taken word for word, no dollar of it meaning anything.

ReplaceAll = fn(b, repl)source

ReplaceAllLiteral = fn(b, repl)source

ReplaceAllFunc = fn(b, f)source

Split = fn(s, n)source

Split slices s around every match, into at most n pieces when n >= 0.