go2hx

manual

github

Module: stdgo.regexp

(view library index)

Overview

Package regexp implements regular expression search.

The syntax of the regular expressions accepted is the same general syntax used by Perl, Python, and other languages. More precisely, it is the syntax accepted by RE2 and described at https://golang.org/s/re2syntax, except for \C. For an overview of the syntax, run

	go doc regexp/syntax

The regexp implementation provided by this package is guaranteed to run in time linear in the size of the input. (This is a property not guaranteed by most open source implementations of regular expressions.) For more information about this property, see

	https://swtch.com/~rsc/regexp/regexp1.html

or any book about automata theory.

All characters are UTF-8-encoded code points. Following utf8.DecodeRune, each byte of an invalid UTF-8 sequence is treated as if it encoded utf8.RuneError (U+FFFD).

There are 16 methods of Regexp that match a regular expression and identify the matched text. Their names are matched by this regular expression:

	Find(All)?(String)?(Submatch)?(Index)?

If 'All' is present, the routine matches successive non-overlapping matches of the entire expression. Empty matches abutting a preceding match are ignored. The return value is a slice containing the successive return values of the corresponding non-'All' routine. These routines take an extra integer argument, n. If n \>= 0, the function returns at most n matches/submatches; otherwise, it returns all of them.

If 'String' is present, the argument is a string; otherwise it is a slice of bytes; return values are adjusted as appropriate.

If 'Submatch' is present, the return value is a slice identifying the successive submatches of the expression. Submatches are matches of parenthesized subexpressions (also known as capturing groups) within the regular expression, numbered from left to right in order of opening parenthesis. Submatch 0 is the match of the entire expression, submatch 1 is the match of the first parenthesized subexpression, and so on.

If 'Index' is present, matches and submatches are identified by byte index pairs within the input string: result[2*n:2*n+2] identifies the indexes of the nth submatch. The pair for n==0 identifies the match of the entire expression. If 'Index' is not present, the match is identified by the text of the match/submatch. If an index is negative or text is nil, it means that subexpression did not match any string in the input. For 'String' versions an empty string means either no match or an empty match.

There is also a subset of the methods that can be applied to text read from a RuneReader:

	MatchReader, FindReaderIndex, FindReaderSubmatchIndex

This set may grow. Note that regular expression matches may need to examine text beyond the text returned by a match, so the methods that match text from a RuneReader may read arbitrarily far into the input before returning.

(There are a few other methods that do not match this pattern.)

Index

Examples

Constants

import stdgo.regexp.Regexp
final _endOfText:stdgo.GoInt32 = ((-1 : stdgo.GoInt32))
final _maxBacktrackProg:stdgo.GoUInt64 = ((500i64 : stdgo.GoUInt64))

len(prog.Inst) \<= max

final _maxBacktrackVector:stdgo.GoUInt64 = ((262144i64 : stdgo.GoUInt64))

bit vector size \<= max (bits)

final _mergeFailed:stdgo.GoUInt32 = ((-1u32 : stdgo.GoUInt32))

mergeRuneSets merges two non-intersecting runesets, and returns the merged result, and a NextIp array. The idea is that if a rune matches the OnePassRunes at index i, NextIp[i/2] is the target. If the input sets intersect, an empty runeset and a NextIp array with the single element mergeFailed is returned. The code assumes that both inputs contain ordered and non-intersecting rune pairs.

final _startSize:stdgo.GoUInt64 = ((10i64 : stdgo.GoUInt64))

The size at which to start a slice in the 'All' routines.

final _visitedBits:stdgo.GoUInt64 = ((32i64 : stdgo.GoUInt64))

Variables

import stdgo.regexp.Regexp
var _:Bool
var _anyRune:stdgo.Slice<stdgo.GoInt32>
var _anyRuneNotNL:stdgo.Slice<stdgo.GoInt32>
var _arrayNoInts:stdgo.GoArray<stdgo.GoInt>

arrayNoInts is returned by doExecute match if nil dstCap is passed to it with ncap=0.

var _badRe:stdgo.Slice<stdgo.regexp.T_stringError>
var _benchData:stdgo.Slice<stdgo.regexp.T__struct_2>
var _benchSizes:stdgo.Slice<stdgo.regexp.T__struct_4>
var _bitStatePool:stdgo.sync.Pool
var _compileBenchData:stdgo.Slice<stdgo.regexp.T__struct_2>
var _emptySubexpIndices:stdgo.Slice<stdgo.regexp.T_subexpIndex>
var _findTests:stdgo.Slice<stdgo.regexp.FindTest>
var _goodRe:stdgo.Slice<stdgo.GoString>
var _literalPrefixTests:stdgo.Slice<stdgo.regexp.MetaTest>
var _match:stdgo.Slice<(:stdgo.Ref<stdgo.regexp.Regexp>, :stdgo.Ref<stdgo.regexp.Regexp>, :stdgo.GoString):{
	_1:stdgo.GoString;
	_0:Bool;
}>
var _matchPool:stdgo.GoArray<stdgo.sync.Pool>

Pools of \machine for use during (\Regexp).doExecute, split up by the size of the execution queues. matchPool[i] machines have queue size matchSize[i]. On a 64-bit system each queue entry is 16 bytes, so matchPool[0] has 16\2\128 = 4kB queues, etc. The final matchPool is a catch-all for very large queues.

var _matchSize:stdgo.GoArray<stdgo.GoInt>

Pools of \machine for use during (\Regexp).doExecute, split up by the size of the execution queues. matchPool[i] machines have queue size matchSize[i]. On a 64-bit system each queue entry is 16 bytes, so matchPool[0] has 16\2\128 = 4kB queues, etc. The final matchPool is a catch-all for very large queues.

var _metaTests:stdgo.Slice<stdgo.regexp.MetaTest>
var _minInputLenTests:stdgo.Slice<stdgo.regexp.T__struct_3>
var _noNext:stdgo.Slice<stdgo.GoUInt32>
var _noRune:stdgo.Slice<stdgo.GoInt32>
var _notab:stdgo.Ref<stdgo.regexp.Regexp>
var _onePassPool:stdgo.sync.Pool
var _onePassTests:stdgo.Slice<stdgo.regexp.T__struct_6>
var _onePassTests1:stdgo.Slice<stdgo.regexp.T__struct_7>

TODO(cespare): Unify with onePassTests and rationalize one-pass test cases.

var _replaceFuncTests:stdgo.Slice<stdgo.regexp.ReplaceFuncTest>
var _replaceLiteralTests:stdgo.Slice<stdgo.regexp.ReplaceTest>
var _replaceTests:stdgo.Slice<stdgo.regexp.ReplaceTest>
var _run:stdgo.Slice<(:stdgo.Ref<stdgo.regexp.Regexp>, :stdgo.Ref<stdgo.regexp.Regexp>, :stdgo.GoString):{
	_1:stdgo.GoString;
	_0:stdgo.Slice<stdgo.GoInt>;
}>
var _runeMergeTests:stdgo.Slice<stdgo.regexp.T__struct_5>
var _sink:stdgo.GoString
var _specialBytes:stdgo.GoArray<stdgo.GoByte>

Bitmap used by func special to check whether a character needs to be escaped.

var _splitTests:stdgo.Slice<stdgo.regexp.T__struct_0>
var _subexpCases:stdgo.Slice<stdgo.regexp.T_subexpCase>
var _text:stdgo.Slice<stdgo.GoByte>

Functions

import stdgo.regexp.Regexp

function _build

function _build(_n:stdgo.GoInt, _x:haxe.Rest<stdgo.GoInt>):stdgo.Slice<stdgo.Slice<stdgo.GoInt>>

build is a helper to construct a [][]int by extracting n sequences from x. This represents n matches with len(x)/n submatches each.

(view code)

function _cleanupOnePass

function _cleanupOnePass(_prog:stdgo.Ref<stdgo.regexp.T_onePassProg>, _original:stdgo.Ref<stdgo.regexp.syntax.Prog>):Void

cleanupOnePass drops working memory, and restores certain shortcut instructions.

(view code)

function _compile

function _compile(_expr:stdgo.GoString, _mode:stdgo.regexp.syntax.Flags, _longest:Bool):{
	_1:stdgo.Error;
	_0:stdgo.Ref<stdgo.regexp.Regexp>;
}

(view code)

function _compileOnePass

function _compileOnePass(_prog:stdgo.Ref<stdgo.regexp.syntax.Prog>):stdgo.Ref<stdgo.regexp.T_onePassProg>

compileOnePass returns a new *syntax.Prog suitable for onePass execution if the original Prog can be recharacterized as a one-pass regexp program, or syntax.nil if the Prog cannot be converted. For a one pass prog, the fundamental condition that must be true is: at any InstAlt, there must be no ambiguity about what branch to take.

(view code)

function _compileTest

function _compileTest(_t:stdgo.Ref<stdgo.testing.T_>, _expr:stdgo.GoString, _error:stdgo.GoString):stdgo.Ref<stdgo.regexp.Regexp>

(view code)

function _copyMatchTest

function _copyMatchTest(_t:stdgo.Ref<stdgo.testing.T_>, _test:stdgo.Ref<stdgo.regexp.FindTest>):Void

(view code)

function _extract

function _extract(_str:stdgo.GoString):{
	_3:Bool;
	_2:stdgo.GoString;
	_1:stdgo.GoInt;
	_0:stdgo.GoString;
}

extract returns the name from a leading "name" or "{name}" in str. (The $ has already been removed by the caller.) If it is a number, extract returns num set to that number; otherwise num = -1.

(view code)

function _freeBitState

function _freeBitState(_b:stdgo.Ref<stdgo.regexp.T_bitState>):Void

(view code)

function _freeOnePassMachine

function _freeOnePassMachine(_m:stdgo.Ref<stdgo.regexp.T_onePassMachine>):Void

(view code)

function _iop

function _iop(_i:stdgo.Ref<stdgo.regexp.syntax.Inst>):stdgo.regexp.syntax.InstOp

(view code)

function _isSingleBytes

function _isSingleBytes(_s:stdgo.GoString):Bool

(view code)

function _makeOnePass

function _makeOnePass(_p:stdgo.Ref<stdgo.regexp.T_onePassProg>):stdgo.Ref<stdgo.regexp.T_onePassProg>

makeOnePass creates a onepass Prog, if possible. It is possible if at any alt, the match engine can always tell which branch to take. The routine may modify p if it is turned into a onepass Prog. If it isn't possible for this to be a onepass Prog, the Prog nil is returned. makeOnePass is recursive to the size of the Prog.

(view code)

function _makeText

function _makeText(_n:stdgo.GoInt):stdgo.Slice<stdgo.GoByte>

(view code)

function _matchFull

function _matchFull(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:Bool;
}

(view code)

function _matchFullLongest

function _matchFullLongest(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:Bool;
}

(view code)

function _matchFunctionTest

function _matchFunctionTest(_t:stdgo.Ref<stdgo.testing.T_>, _test:stdgo.Ref<stdgo.regexp.FindTest>):Void

(view code)

function _matchPartial

function _matchPartial(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:Bool;
}

(view code)

function _matchPartialLongest

function _matchPartialLongest(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:Bool;
}

(view code)

function _matchTest

function _matchTest(_t:stdgo.Ref<stdgo.testing.T_>, _test:stdgo.Ref<stdgo.regexp.FindTest>):Void

(view code)

function _maxBitStateLen

function _maxBitStateLen(_prog:stdgo.Ref<stdgo.regexp.syntax.Prog>):stdgo.GoInt

maxBitStateLen returns the maximum length of a string to search with the backtracker using prog.

(view code)

function _mergeRuneSets

function _mergeRuneSets(_leftRunes:stdgo.Ref<stdgo.Slice<stdgo.GoRune>>, _rightRunes:stdgo.Ref<stdgo.Slice<stdgo.GoRune>>, _leftPC:stdgo.GoUInt32, _rightPC:stdgo.GoUInt32):{
	_1:stdgo.Slice<stdgo.GoUInt32>;
	_0:stdgo.Slice<stdgo.GoRune>;
}

(view code)

function _minInputLen

function _minInputLen(_re:stdgo.Ref<stdgo.regexp.syntax.Regexp>):stdgo.GoInt

minInputLen walks the regexp to find the minimum length of any matchable input.

(view code)

function _newBitState

function _newBitState():stdgo.Ref<stdgo.regexp.T_bitState>

(view code)

function _newLazyFlag

function _newLazyFlag(_r1:stdgo.GoRune, _r2:stdgo.GoRune):stdgo.regexp.T_lazyFlag

(view code)

function _newOnePassMachine

function _newOnePassMachine():stdgo.Ref<stdgo.regexp.T_onePassMachine>

(view code)

function _newQueue

function _newQueue(_size:stdgo.GoInt):stdgo.Ref<stdgo.regexp.T_queueOnePass>

(view code)

function _onePassCopy

function _onePassCopy(_prog:stdgo.Ref<stdgo.regexp.syntax.Prog>):stdgo.Ref<stdgo.regexp.T_onePassProg>

onePassCopy creates a copy of the original Prog, as we'll be modifying it.

(view code)

function _onePassNext

function _onePassNext(_i:stdgo.Ref<stdgo.regexp.T_onePassInst>, _r:stdgo.GoRune):stdgo.GoUInt32

onePassNext selects the next actionable state of the prog, based on the input character. It should only be called when i.Op == InstAlt or InstAltMatch, and from the one-pass machine. One of the alternates may ultimately lead without input to end of line. If the instruction is InstAltMatch the path to the InstMatch is in i.Out, the normal node in i.Next.

(view code)

function _onePassPrefix

function _onePassPrefix(_p:stdgo.Ref<stdgo.regexp.syntax.Prog>):{
	_2:stdgo.GoUInt32;
	_1:Bool;
	_0:stdgo.GoString;
}

onePassPrefix returns a literal string that all matches for the regexp must start with. Complete is true if the prefix is the entire match. Pc is the index of the last rune instruction in the string. The onePassPrefix skips over the mandatory EmptyBeginText.

(view code)

function _parseFowlerResult

function _parseFowlerResult(_s:stdgo.GoString):{
	_3:stdgo.Slice<stdgo.GoInt>;
	_2:Bool;
	_1:Bool;
	_0:Bool;
}

(view code)

function _parseResult

function _parseResult(_t:stdgo.Ref<stdgo.testing.T_>, _file:stdgo.GoString, _lineno:stdgo.GoInt, _res:stdgo.GoString):stdgo.Slice<stdgo.GoInt>

(view code)

function _quote

function _quote(_s:stdgo.GoString):stdgo.GoString

(view code)

function _runFull

function _runFull(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:stdgo.Slice<stdgo.GoInt>;
}

(view code)

function _runFullLongest

function _runFullLongest(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:stdgo.Slice<stdgo.GoInt>;
}

(view code)

function _runPartial

function _runPartial(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:stdgo.Slice<stdgo.GoInt>;
}

(view code)

function _runPartialLongest

function _runPartialLongest(_re:stdgo.Ref<stdgo.regexp.Regexp>, _refull:stdgo.Ref<stdgo.regexp.Regexp>, _text:stdgo.GoString):{
	_1:stdgo.GoString;
	_0:stdgo.Slice<stdgo.GoInt>;
}

(view code)

function _same

function _same(_x:stdgo.Slice<stdgo.GoInt>, _y:stdgo.Slice<stdgo.GoInt>):Bool

(view code)

function _shouldBacktrack

function _shouldBacktrack(_prog:stdgo.Ref<stdgo.regexp.syntax.Prog>):Bool

shouldBacktrack reports whether the program is too long for the backtracker to run.

(view code)

function _special

function _special(_b:stdgo.GoByte):Bool

special reports whether byte b needs to be escaped by QuoteMeta.

(view code)

function _testFindAllIndex

function _testFindAllIndex(_test:stdgo.Ref<stdgo.regexp.FindTest>, _result:stdgo.Slice<stdgo.Slice<stdgo.GoInt>>, _t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function _testFindAllSubmatchIndex

function _testFindAllSubmatchIndex(_test:stdgo.Ref<stdgo.regexp.FindTest>, _result:stdgo.Slice<stdgo.Slice<stdgo.GoInt>>, _t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function _testFindIndex

function _testFindIndex(_test:stdgo.Ref<stdgo.regexp.FindTest>, _result:stdgo.Slice<stdgo.GoInt>, _t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function _testFindSubmatchIndex

function _testFindSubmatchIndex(_test:stdgo.Ref<stdgo.regexp.FindTest>, _result:stdgo.Slice<stdgo.GoInt>, _t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function _testFowler

function _testFowler(_t:stdgo.Ref<stdgo.testing.T_>, _file:stdgo.GoString):Void

(view code)

function _testRE2

function _testRE2(_t:stdgo.Ref<stdgo.testing.T_>, _file:stdgo.GoString):Void

(view code)

function _testSubmatchBytes

function _testSubmatchBytes(_test:stdgo.Ref<stdgo.regexp.FindTest>, _n:stdgo.GoInt, _submatches:stdgo.Slice<stdgo.GoInt>, _result:stdgo.Slice<stdgo.Slice<stdgo.GoByte>>, _t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function _testSubmatchIndices

function _testSubmatchIndices(_test:stdgo.Ref<stdgo.regexp.FindTest>, _n:stdgo.GoInt, _expect:stdgo.Slice<stdgo.GoInt>, _result:stdgo.Slice<stdgo.GoInt>, _t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function _testSubmatchString

function _testSubmatchString(_test:stdgo.Ref<stdgo.regexp.FindTest>, _n:stdgo.GoInt, _submatches:stdgo.Slice<stdgo.GoInt>, _result:stdgo.Slice<stdgo.GoString>, _t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function _tryCompile

function _tryCompile(_s:stdgo.GoString):{
	_1:stdgo.Error;
	_0:stdgo.Ref<stdgo.regexp.Regexp>;
}

(view code)

function benchmarkAnchoredLiteralLongNonMatch

function benchmarkAnchoredLiteralLongNonMatch(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkAnchoredLiteralShortNonMatch

function benchmarkAnchoredLiteralShortNonMatch(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkAnchoredLongMatch

function benchmarkAnchoredLongMatch(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkAnchoredShortMatch

function benchmarkAnchoredShortMatch(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkCompile

function benchmarkCompile(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkFind

function benchmarkFind(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkFindAllNoMatches

function benchmarkFindAllNoMatches(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkFindString

function benchmarkFindString(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkFindStringSubmatch

function benchmarkFindStringSubmatch(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkFindSubmatch

function benchmarkFindSubmatch(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkLiteral

function benchmarkLiteral(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkMatch

function benchmarkMatch(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkMatchClass

function benchmarkMatchClass(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkMatchClass_InRange

function benchmarkMatchClass_InRange(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkMatchParallelCopied

function benchmarkMatchParallelCopied(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkMatchParallelShared

function benchmarkMatchParallelShared(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkMatch_onepass_regex

function benchmarkMatch_onepass_regex(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkNotLiteral

function benchmarkNotLiteral(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkNotOnePassShortA

function benchmarkNotOnePassShortA(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkNotOnePassShortB

function benchmarkNotOnePassShortB(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkOnePassLongNotPrefix

function benchmarkOnePassLongNotPrefix(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkOnePassLongPrefix

function benchmarkOnePassLongPrefix(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkOnePassShortA

function benchmarkOnePassShortA(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkOnePassShortB

function benchmarkOnePassShortB(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkQuoteMetaAll

function benchmarkQuoteMetaAll(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkQuoteMetaNone

function benchmarkQuoteMetaNone(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function benchmarkReplaceAll

function benchmarkReplaceAll(_b:stdgo.Ref<stdgo.testing.B>):Void

(view code)

function compile

function compile(_expr:stdgo.GoString):{
	_1:stdgo.Error;
	_0:stdgo.Ref<stdgo.regexp.Regexp>;
}

Compile parses a regular expression and returns, if successful, a Regexp object that can be used to match against text.

When matching against text, the regexp returns a match that begins as early as possible in the input (leftmost), and among those it chooses the one that a backtracking search would have found first. This so-called leftmost-first matching is the same semantics that Perl, Python, and other implementations use, although this package implements it without the expense of backtracking. For POSIX leftmost-longest matching, see CompilePOSIX.

(view code)

function compilePOSIX

function compilePOSIX(_expr:stdgo.GoString):{
	_1:stdgo.Error;
	_0:stdgo.Ref<stdgo.regexp.Regexp>;
}

CompilePOSIX is like Compile but restricts the regular expression to POSIX ERE (egrep) syntax and changes the match semantics to leftmost-longest.

That is, when matching against text, the regexp returns a match that begins as early as possible in the input (leftmost), and among those it chooses a match that is as long as possible. This so-called leftmost-longest matching is the same semantics that early regular expression implementations used and that POSIX specifies.

However, there can be multiple leftmost-longest matches, with different submatch choices, and here this package diverges from POSIX. Among the possible leftmost-longest matches, this package chooses the one that a backtracking search would have found first, while POSIX specifies that the match be chosen to maximize the length of the first subexpression, then the second, and so on from left to right. The POSIX rule is computationally prohibitive and not even well-defined. See https://swtch.com/~rsc/regexp/regexp2.html#posix for details.

(view code)

function match

function match(_pattern:stdgo.GoString, _b:stdgo.Slice<stdgo.GoByte>):{
	_1:stdgo.Error;
	_0:Bool;
}

Match reports whether the byte slice b contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

exampleMatch

function exampleMatch():Void {
        var __tmp__ = stdgo.regexp.Regexp.match(("foo.*" : stdgo.GoString), (("seafood" : stdgo.GoString) : stdgo.Slice<stdgo.GoByte>)), _matched:Bool = __tmp__._0, _err:stdgo.Error = __tmp__._1;
        stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_matched), stdgo.Go.toInterface(_err));
        {
            var __tmp__ = stdgo.regexp.Regexp.match(("bar.*" : stdgo.GoString), (("seafood" : stdgo.GoString) : stdgo.Slice<stdgo.GoByte>));
            _matched = __tmp__._0;
            _err = __tmp__._1;
        };
        stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_matched), stdgo.Go.toInterface(_err));
        {
            var __tmp__ = stdgo.regexp.Regexp.match(("a(b" : stdgo.GoString), (("seafood" : stdgo.GoString) : stdgo.Slice<stdgo.GoByte>));
            _matched = __tmp__._0;
            _err = __tmp__._1;
        };
        stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_matched), stdgo.Go.toInterface(_err));
    }

(view code)

function matchReader

function matchReader(_pattern:stdgo.GoString, _r:stdgo.io.RuneReader):{
	_1:stdgo.Error;
	_0:Bool;
}

MatchReader reports whether the text returned by the RuneReader contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

(view code)

function matchString

function matchString(_pattern:stdgo.GoString, _s:stdgo.GoString):{
	_1:stdgo.Error;
	_0:Bool;
}

MatchString reports whether the string s contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

exampleMatchString

function exampleMatchString():Void {
        var __tmp__ = stdgo.regexp.Regexp.matchString(("foo.*" : stdgo.GoString), ("seafood" : stdgo.GoString)), _matched:Bool = __tmp__._0, _err:stdgo.Error = __tmp__._1;
        stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_matched), stdgo.Go.toInterface(_err));
        {
            var __tmp__ = stdgo.regexp.Regexp.matchString(("bar.*" : stdgo.GoString), ("seafood" : stdgo.GoString));
            _matched = __tmp__._0;
            _err = __tmp__._1;
        };
        stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_matched), stdgo.Go.toInterface(_err));
        {
            var __tmp__ = stdgo.regexp.Regexp.matchString(("a(b" : stdgo.GoString), ("seafood" : stdgo.GoString));
            _matched = __tmp__._0;
            _err = __tmp__._1;
        };
        stdgo.fmt.Fmt.println(stdgo.Go.toInterface(_matched), stdgo.Go.toInterface(_err));
    }

(view code)

function mustCompile

function mustCompile(_str:stdgo.GoString):stdgo.Ref<stdgo.regexp.Regexp>

MustCompile is like Compile but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled regular expressions.

(view code)

function mustCompilePOSIX

function mustCompilePOSIX(_str:stdgo.GoString):stdgo.Ref<stdgo.regexp.Regexp>

MustCompilePOSIX is like CompilePOSIX but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled regular expressions.

(view code)

function quoteMeta

function quoteMeta(_s:stdgo.GoString):stdgo.GoString

QuoteMeta returns a string that escapes all regular expression metacharacters inside the argument text; the returned string is a regular expression matching the literal text.

exampleQuoteMeta

function exampleQuoteMeta():Void {
        stdgo.fmt.Fmt.println(stdgo.Go.toInterface(stdgo.regexp.Regexp.quoteMeta(("Escaping symbols like: .+*?()|[]{}^$" : stdgo.GoString))));
    }

(view code)

function testBadCompile

function testBadCompile(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testCompileOnePass

function testCompileOnePass(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testCopyMatch

function testCopyMatch(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testDeepEqual

function testDeepEqual(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFind

function testFind(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAll

function testFindAll(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAllIndex

function testFindAllIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAllString

function testFindAllString(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAllStringIndex

function testFindAllStringIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAllStringSubmatch

function testFindAllStringSubmatch(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAllStringSubmatchIndex

function testFindAllStringSubmatchIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAllSubmatch

function testFindAllSubmatch(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindAllSubmatchIndex

function testFindAllSubmatchIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindIndex

function testFindIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindReaderIndex

function testFindReaderIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindReaderSubmatchIndex

function testFindReaderSubmatchIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindString

function testFindString(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindStringIndex

function testFindStringIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindStringSubmatch

function testFindStringSubmatch(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindStringSubmatchIndex

function testFindStringSubmatchIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindSubmatch

function testFindSubmatch(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFindSubmatchIndex

function testFindSubmatchIndex(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testFowler

function testFowler(_t:stdgo.Ref<stdgo.testing.T_>):Void

TestFowler runs this package's regexp API against the POSIX regular expression tests collected by Glenn Fowler at http://www2.research.att.com/~astopen/testregex/testregex.html.

(view code)

function testGoodCompile

function testGoodCompile(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testLiteralPrefix

function testLiteralPrefix(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testLongest

function testLongest(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testMatch

function testMatch(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testMatchFunction

function testMatchFunction(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testMergeRuneSet

function testMergeRuneSet(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testMinInputLen

function testMinInputLen(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testOnePassCutoff

function testOnePassCutoff(_t:stdgo.Ref<stdgo.testing.T_>):Void

Check that one-pass cutoff does trigger.

(view code)

function testParseAndCompile

function testParseAndCompile(_t:stdgo.Ref<stdgo.testing.T_>):Void

The following sequence of Match calls used to panic. See issue #12980.

(view code)

function testProgramTooLongForBacktrack

function testProgramTooLongForBacktrack(_t:stdgo.Ref<stdgo.testing.T_>):Void

TestProgramTooLongForBacktrack tests that a regex which is too long for the backtracker still executes properly.

(view code)

function testQuoteMeta

function testQuoteMeta(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testRE2Exhaustive

function testRE2Exhaustive(_t:stdgo.Ref<stdgo.testing.T_>):Void

This test is excluded when running under the race detector because it is a very expensive test and takes too long.

(view code)

function testRE2Search

function testRE2Search(_t:stdgo.Ref<stdgo.testing.T_>):Void

TestRE2 tests this package's regexp API against test cases considered during RE2's exhaustive tests, which run all possible regexps over a given set of atoms and operators, up to a given complexity, over all possible strings over a given alphabet, up to a given size. Rather than try to link with RE2, we read a log file containing the test cases and the expected matches. The log file, re2-exhaustive.txt, is generated by running 'make log' in the open source RE2 distribution https://github.com/google/re2/.

The test file format is a sequence of stanzas like:

	strings
	"abc"
	"123x"
	regexps
	"[a-z]+"
	0-3;0-3
	-;-
	"([0-9])([0-9])([0-9])"
	-;-
	-;0-3 0-1 1-2 2-3

The stanza begins by defining a set of strings, quoted using Go double-quote syntax, one per line. Then the regexps section gives a sequence of regexps to run on the strings. In the block that follows a regexp, each line gives the semicolon-separated match results of running the regexp on the corresponding string. Each match result is either a single -, meaning no match, or a space-separated sequence of pairs giving the match and submatch indices. An unmatched subexpression formats its pair as a single - (not illustrated above). For now each regexp run produces two match results, one for a “full match” that restricts the regexp to matching the entire string or nothing, and one for a “partial match” that gives the leftmost first match found in the string.

Lines beginning with # are comments. Lines beginning with a capital letter are test names printed during RE2's test suite and are echoed into t but otherwise ignored.

At time of writing, re2-exhaustive.txt is 59 MB but compresses to 385 kB, so we store re2-exhaustive.txt.bz2 in the repository and decompress it on the fly.

(view code)

function testReplaceAll

function testReplaceAll(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testReplaceAllFunc

function testReplaceAllFunc(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testReplaceAllLiteral

function testReplaceAllLiteral(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testRunOnePass

function testRunOnePass(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testSplit

function testSplit(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testSubexp

function testSubexp(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

function testSwitchBacktrack

function testSwitchBacktrack(_t:stdgo.Ref<stdgo.testing.T_>):Void

Check that the same machine can be used with the standard matcher and then the backtracker when there are no captures.

(view code)

function testUnmarshalText

function testUnmarshalText(_t:stdgo.Ref<stdgo.testing.T_>):Void

(view code)

Classes

import stdgo.regexp.*

class FindTest

For each pattern/text pair, what is the expected output of each function? We can derive the textual results from the indexed results, the non-submatch results from the submatched results, the single results from the 'all' results, and the byte results from the string results. Therefore the table includes only the FindAllStringSubmatchIndex result.

var _matches:stdgo.Slice<stdgo.Slice<stdgo.GoInt>>
var _pat:stdgo.GoString
var _text:stdgo.GoString

FindTest function new

function new(?_pat:stdgo.GoString, ?_text:stdgo.GoString, ?_matches:stdgo.Slice<stdgo.Slice<stdgo.GoInt>>):Void

(view code)

FindTest function string

function string():stdgo.GoString

(view code)

class MetaTest

var _isLiteral:Bool
var _literal:stdgo.GoString
var _output:stdgo.GoString
var _pattern:stdgo.GoString

MetaTest function new

function new(?_pattern:stdgo.GoString, ?_output:stdgo.GoString, ?_literal:stdgo.GoString, ?_isLiteral:Bool):Void

(view code)

class Regexp

Regexp is the representation of a compiled regular expression. A Regexp is safe for concurrent use by multiple goroutines, except for configuration methods, such as Longest.

var _cond:stdgo.regexp.syntax.EmptyOp
var _expr:stdgo.GoString
var _longest:Bool

This field can be modified by the Longest method, but it is otherwise read-only.

var _matchcap:stdgo.GoInt
var _maxBitStateLen:stdgo.GoInt
var _minInputLen:stdgo.GoInt
var _mpool:stdgo.GoInt
var _numSubexp:stdgo.GoInt
var _onepass:stdgo.Ref<stdgo.regexp.T_onePassProg>
var _prefix:stdgo.GoString
var _prefixBytes:stdgo.Slice<stdgo.GoUInt8>
var _prefixComplete:Bool
var _prefixEnd:stdgo.GoUInt32
var _prefixRune:stdgo.GoInt32
var _prog:stdgo.Ref<stdgo.regexp.syntax.Prog>
var _subexpNames:stdgo.Slice<stdgo.GoString>

Regexp function new

function new(?_expr:stdgo.GoString, ?_prog:stdgo.Ref<stdgo.regexp.syntax.Prog>, ?_onepass:stdgo.Ref<stdgo.regexp.T_onePassProg>, ?_numSubexp:stdgo.GoInt, ?_maxBitStateLen:stdgo.GoInt, ?_subexpNames:stdgo.Slice<stdgo.GoString>, ?_prefix:stdgo.GoString, ?_prefixBytes:stdgo.Slice<stdgo.GoUInt8>, ?_prefixRune:stdgo.GoInt32, ?_prefixEnd:stdgo.GoUInt32, ?_mpool:stdgo.GoInt, ?_matchcap:stdgo.GoInt, ?_prefixComplete:Bool, ?_cond:Null<stdgo.regexp.syntax.EmptyOp>, ?_minInputLen:stdgo.GoInt, ?_longest:Bool):Void

(view code)

Regexp function _allMatches

function _allMatches( _s:stdgo.GoString, _b:stdgo.Slice<stdgo.GoByte>, _n:stdgo.GoInt, _deliver:()):Void

allMatches calls deliver at most n times with the location of successive matches in the input text. The input text is b if non-nil, otherwise s.

(view code)

Regexp function _backtrack

function _backtrack( _ib:stdgo.Slice<stdgo.GoByte>, _is:stdgo.GoString, _pos:stdgo.GoInt, _ncap:stdgo.GoInt, _dstCap:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoInt>

backtrack runs a backtracking search of prog on the input starting at pos.

(view code)

Regexp function _doExecute

function _doExecute( _r:stdgo.io.RuneReader, _b:stdgo.Slice<stdgo.GoByte>, _s:stdgo.GoString, _pos:stdgo.GoInt, _ncap:stdgo.GoInt, _dstCap:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoInt>

doExecute finds the leftmost match in the input, appends the position of its subexpressions to dstCap and returns dstCap.

nil is returned if no matches are found and non-nil if matches are found.

(view code)

Regexp function _doMatch

function _doMatch( _r:stdgo.io.RuneReader, _b:stdgo.Slice<stdgo.GoByte>, _s:stdgo.GoString):Bool

doMatch reports whether either r, b or s match the regexp.

(view code)

Regexp function _doOnePass

function _doOnePass( _ir:stdgo.io.RuneReader, _ib:stdgo.Slice<stdgo.GoByte>, _is:stdgo.GoString, _pos:stdgo.GoInt, _ncap:stdgo.GoInt, _dstCap:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoInt>

doOnePass implements r.doExecute using the one-pass execution engine.

(view code)

Regexp function _expand

function _expand( _dst:stdgo.Slice<stdgo.GoByte>, _template:stdgo.GoString, _bsrc:stdgo.Slice<stdgo.GoByte>, _src:stdgo.GoString, _match:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoByte>

(view code)

Regexp function _get

function _get():stdgo.Ref<stdgo.regexp.T_machine>

get returns a machine to use for matching re. It uses the re's machine cache if possible, to avoid unnecessary allocation.

(view code)

Regexp function _pad

function _pad( _a:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoInt>

The number of capture values in the program may correspond to fewer capturing expressions than are in the regexp. For example, "(a){0}" turns into an empty program, so the maximum capture in the program is 0 but we need to return an expression for \1. Pad appends -1s to the slice a as needed.

(view code)

Regexp function _put

function _put( _m:stdgo.Ref<stdgo.regexp.T_machine>):Void

put returns a machine to the correct machine pool.

(view code)

Regexp function _replaceAll

function _replaceAll( _bsrc:stdgo.Slice<stdgo.GoByte>, _src:stdgo.GoString, _nmatch:stdgo.GoInt, _repl:(_dst:stdgo.Slice<stdgo.GoByte>, _m:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoByte>):stdgo.Slice<stdgo.GoByte>

(view code)

Regexp function _tryBacktrack

function _tryBacktrack( _b:stdgo.Ref<stdgo.regexp.T_bitState>, _i:stdgo.regexp.T_input, _pc:stdgo.GoUInt32, _pos:stdgo.GoInt):Bool

tryBacktrack runs a backtracking search starting at pos.

(view code)

Regexp function copy

function copy():stdgo.Ref<stdgo.regexp.Regexp>

Copy returns a new Regexp object copied from re. Calling Longest on one copy does not affect another.

Deprecated: In earlier releases, when using a Regexp in multiple goroutines, giving each goroutine its own copy helped to avoid lock contention. As of Go 1.12, using Copy is no longer necessary to avoid lock contention. Copy may still be appropriate if the reason for its use is to make two copies with different Longest settings.

(view code)

Regexp function expand

function expand( _dst:stdgo.Slice<stdgo.GoByte>, _template:stdgo.Slice<stdgo.GoByte>, _src:stdgo.Slice<stdgo.GoByte>, _match:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoByte>

Expand appends template to dst and returns the result; during the append, Expand replaces variables in the template with corresponding matches drawn from src. The match slice should have been returned by FindSubmatchIndex.

In the template, a variable is denoted by a substring of the form $name or ${name}, where name is a non-empty sequence of letters, digits, and underscores. A purely numeric name like $1 refers to the submatch with the corresponding index; other names refer to capturing parentheses named with the (?P\...) syntax. A reference to an out of range or unmatched index or a name that is not present in the regular expression is replaced with an empty slice.

In the $name form, name is taken to be as long as possible: $1x is equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0.

To insert a literal $ in the output, use $$ in the template.

(view code)

Regexp function expandString

function expandString( _dst:stdgo.Slice<stdgo.GoByte>, _template:stdgo.GoString, _src:stdgo.GoString, _match:stdgo.Slice<stdgo.GoInt>):stdgo.Slice<stdgo.GoByte>

ExpandString is like Expand but the template and source are strings. It appends to and returns a byte slice in order to give the calling code control over allocation.

(view code)

Regexp function find

function find( _b:stdgo.Slice<stdgo.GoByte>):stdgo.Slice<stdgo.GoByte>

Find returns a slice holding the text of the leftmost match in b of the regular expression. A return value of nil indicates no match.

(view code)

Regexp function findAll

function findAll( _b:stdgo.Slice<stdgo.GoByte>, _n:stdgo.GoInt):stdgo.Slice<stdgo.Slice<stdgo.GoByte>>

FindAll is the 'All' version of Find; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findAllIndex

function findAllIndex( _b:stdgo.Slice<stdgo.GoByte>, _n:stdgo.GoInt):stdgo.Slice<stdgo.Slice<stdgo.GoInt>>

FindAllIndex is the 'All' version of FindIndex; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findAllString

function findAllString( _s:stdgo.GoString, _n:stdgo.GoInt):stdgo.Slice<stdgo.GoString>

FindAllString is the 'All' version of FindString; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findAllStringIndex

function findAllStringIndex( _s:stdgo.GoString, _n:stdgo.GoInt):stdgo.Slice<stdgo.Slice<stdgo.GoInt>>

FindAllStringIndex is the 'All' version of FindStringIndex; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findAllStringSubmatch

function findAllStringSubmatch( _s:stdgo.GoString, _n:stdgo.GoInt):stdgo.Slice<stdgo.Slice<stdgo.GoString>>

FindAllStringSubmatch is the 'All' version of FindStringSubmatch; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findAllStringSubmatchIndex

function findAllStringSubmatchIndex( _s:stdgo.GoString, _n:stdgo.GoInt):stdgo.Slice<stdgo.Slice<stdgo.GoInt>>

FindAllStringSubmatchIndex is the 'All' version of FindStringSubmatchIndex; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findAllSubmatch

function findAllSubmatch( _b:stdgo.Slice<stdgo.GoByte>, _n:stdgo.GoInt):stdgo.Slice<stdgo.Slice<stdgo.Slice<stdgo.GoByte>>>

FindAllSubmatch is the 'All' version of FindSubmatch; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findAllSubmatchIndex

function findAllSubmatchIndex( _b:stdgo.Slice<stdgo.GoByte>, _n:stdgo.GoInt):stdgo.Slice<stdgo.Slice<stdgo.GoInt>>

FindAllSubmatchIndex is the 'All' version of FindSubmatchIndex; it returns a slice of all successive matches of the expression, as defined by the 'All' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findIndex

function findIndex( _b:stdgo.Slice<stdgo.GoByte>):stdgo.Slice<stdgo.GoInt>

FindIndex returns a two-element slice of integers defining the location of the leftmost match in b of the regular expression. The match itself is at b[loc[0]:loc[1]]. A return value of nil indicates no match.

(view code)

Regexp function findReaderIndex

function findReaderIndex( _r:stdgo.io.RuneReader):stdgo.Slice<stdgo.GoInt>

FindReaderIndex returns a two-element slice of integers defining the location of the leftmost match of the regular expression in text read from the RuneReader. The match text was found in the input stream at byte offset loc[0] through loc[1]-1. A return value of nil indicates no match.

(view code)

Regexp function findReaderSubmatchIndex

function findReaderSubmatchIndex( _r:stdgo.io.RuneReader):stdgo.Slice<stdgo.GoInt>

FindReaderSubmatchIndex returns a slice holding the index pairs identifying the leftmost match of the regular expression of text read by the RuneReader, and the matches, if any, of its subexpressions, as defined by the 'Submatch' and 'Index' descriptions in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findString

function findString( _s:stdgo.GoString):stdgo.GoString

FindString returns a string holding the text of the leftmost match in s of the regular expression. If there is no match, the return value is an empty string, but it will also be empty if the regular expression successfully matches an empty string. Use FindStringIndex or FindStringSubmatch if it is necessary to distinguish these cases.

(view code)

Regexp function findStringIndex

function findStringIndex( _s:stdgo.GoString):stdgo.Slice<stdgo.GoInt>

FindStringIndex returns a two-element slice of integers defining the location of the leftmost match in s of the regular expression. The match itself is at s[loc[0]:loc[1]]. A return value of nil indicates no match.

(view code)

Regexp function findStringSubmatch

function findStringSubmatch( _s:stdgo.GoString):stdgo.Slice<stdgo.GoString>

FindStringSubmatch returns a slice of strings holding the text of the leftmost match of the regular expression in s and the matches, if any, of its subexpressions, as defined by the 'Submatch' description in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findStringSubmatchIndex

function findStringSubmatchIndex( _s:stdgo.GoString):stdgo.Slice<stdgo.GoInt>

FindStringSubmatchIndex returns a slice holding the index pairs identifying the leftmost match of the regular expression in s and the matches, if any, of its subexpressions, as defined by the 'Submatch' and 'Index' descriptions in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findSubmatch

function findSubmatch( _b:stdgo.Slice<stdgo.GoByte>):stdgo.Slice<stdgo.Slice<stdgo.GoByte>>

FindSubmatch returns a slice of slices holding the text of the leftmost match of the regular expression in b and the matches, if any, of its subexpressions, as defined by the 'Submatch' descriptions in the package comment. A return value of nil indicates no match.

(view code)

Regexp function findSubmatchIndex

function findSubmatchIndex( _b:stdgo.Slice<stdgo.GoByte>):stdgo.Slice<stdgo.GoInt>

FindSubmatchIndex returns a slice holding the index pairs identifying the leftmost match of the regular expression in b and the matches, if any, of its subexpressions, as defined by the 'Submatch' and 'Index' descriptions in the package comment. A return value of nil indicates no match.

(view code)

Regexp function literalPrefix

function literalPrefix():{
	_1:Bool;
	_0:stdgo.GoString;
}

LiteralPrefix returns a literal string that must begin any match of the regular expression re. It returns the boolean true if the literal string comprises the entire regular expression.

(view code)

Regexp function longest

function longest():Void

Longest makes future searches prefer the leftmost-longest match. That is, when matching against text, the regexp returns a match that begins as early as possible in the input (leftmost), and among those it chooses a match that is as long as possible. This method modifies the Regexp and may not be called concurrently with any other methods.

(view code)

Regexp function marshalText

function marshalText():{
	_1:stdgo.Error;
	_0:stdgo.Slice<stdgo.GoByte>;
}

MarshalText implements [encoding.TextMarshaler]. The output matches that of calling the [Regexp.String] method.

Note that the output is lossy in some cases: This method does not indicate POSIX regular expressions (i.e. those compiled by calling [CompilePOSIX]), or those for which the [Regexp.Longest] method has been called.

(view code)

Regexp function match

function match( _b:stdgo.Slice<stdgo.GoByte>):Bool

Match reports whether the byte slice b contains any match of the regular expression re.

(view code)

Regexp function matchReader

function matchReader( _r:stdgo.io.RuneReader):Bool

MatchReader reports whether the text returned by the RuneReader contains any match of the regular expression re.

(view code)

Regexp function matchString

function matchString( _s:stdgo.GoString):Bool

MatchString reports whether the string s contains any match of the regular expression re.

(view code)

Regexp function numSubexp

function numSubexp():stdgo.GoInt

NumSubexp returns the number of parenthesized subexpressions in this Regexp.

(view code)

Regexp function replaceAll

function replaceAll( _src:stdgo.Slice<stdgo.GoByte>, _repl:stdgo.Slice<stdgo.GoByte>):stdgo.Slice<stdgo.GoByte>

ReplaceAll returns a copy of src, replacing matches of the Regexp with the replacement text repl. Inside repl, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.

(view code)

Regexp function replaceAllFunc

function replaceAllFunc( _src:stdgo.Slice<stdgo.GoByte>, _repl:()):stdgo.Slice<stdgo.GoByte>

ReplaceAllFunc returns a copy of src in which all matches of the Regexp have been replaced by the return value of function repl applied to the matched byte slice. The replacement returned by repl is substituted directly, without using Expand.

(view code)

Regexp function replaceAllLiteral

function replaceAllLiteral( _src:stdgo.Slice<stdgo.GoByte>, _repl:stdgo.Slice<stdgo.GoByte>):stdgo.Slice<stdgo.GoByte>

ReplaceAllLiteral returns a copy of src, replacing matches of the Regexp with the replacement bytes repl. The replacement repl is substituted directly, without using Expand.

(view code)

Regexp function replaceAllLiteralString

function replaceAllLiteralString( _src:stdgo.GoString, _repl:stdgo.GoString):stdgo.GoString

ReplaceAllLiteralString returns a copy of src, replacing matches of the Regexp with the replacement string repl. The replacement repl is substituted directly, without using Expand.

(view code)

Regexp function replaceAllString

function replaceAllString( _src:stdgo.GoString, _repl:stdgo.GoString):stdgo.GoString

ReplaceAllString returns a copy of src, replacing matches of the Regexp with the replacement string repl. Inside repl, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.

(view code)

Regexp function replaceAllStringFunc

function replaceAllStringFunc( _src:stdgo.GoString, _repl:()):stdgo.GoString

ReplaceAllStringFunc returns a copy of src in which all matches of the Regexp have been replaced by the return value of function repl applied to the matched substring. The replacement returned by repl is substituted directly, without using Expand.

(view code)

Regexp function split

function split( _s:stdgo.GoString, _n:stdgo.GoInt):stdgo.Slice<stdgo.GoString>

Split slices s into substrings separated by the expression and returns a slice of the substrings between those expression matches.

The slice returned by this method consists of all the substrings of s not contained in the slice returned by FindAllString. When called on an expression that contains no metacharacters, it is equivalent to strings.SplitN.

Example:

	s := regexp.MustCompile("a*").Split("abaabaccadaaae", 5)
	// s: ["", "b", "b", "c", "cadaaae"]

The count determines the number of substrings to return:

	n > 0: at most n substrings; the last substring will be the unsplit remainder.
	n == 0: the result is nil (zero substrings)
	n < 0: all substrings

(view code)

Regexp function string

function string():stdgo.GoString

String returns the source text used to compile the regular expression.

(view code)

Regexp function subexpIndex

function subexpIndex( _name:stdgo.GoString):stdgo.GoInt

SubexpIndex returns the index of the first subexpression with the given name, or -1 if there is no subexpression with that name.

Note that multiple subexpressions can be written using the same name, as in (?P\a+)(?P\b+), which declares two subexpressions named "bob". In this case, SubexpIndex returns the index of the leftmost such subexpression in the regular expression.

(view code)

Regexp function subexpNames

function subexpNames():stdgo.Slice<stdgo.GoString>

SubexpNames returns the names of the parenthesized subexpressions in this Regexp. The name for the first sub-expression is names[1], so that if m is a match slice, the name for m[i] is SubexpNames()[i]. Since the Regexp as a whole cannot be named, names[0] is always the empty string. The slice should not be modified.

(view code)

Regexp function unmarshalText

function unmarshalText( _text:stdgo.Slice<stdgo.GoByte>):stdgo.Error

UnmarshalText implements [encoding.TextUnmarshaler] by calling [Compile] on the encoded value.

(view code)

class ReplaceFuncTest

var _input:stdgo.GoString
var _output:stdgo.GoString
var _pattern:stdgo.GoString

ReplaceFuncTest function _replacement

function _replacement()

ReplaceFuncTest function new

function new(?_pattern:stdgo.GoString, ?_replacement:(), ?_input:stdgo.GoString, ?_output:stdgo.GoString):Void

(view code)

class ReplaceTest

var _input:stdgo.GoString
var _output:stdgo.GoString
var _pattern:stdgo.GoString
var _replacement:stdgo.GoString

ReplaceTest function new

function new(?_pattern:stdgo.GoString, ?_replacement:stdgo.GoString, ?_input:stdgo.GoString, ?_output:stdgo.GoString):Void

(view code)

Typedefs

import stdgo.regexp.*

typedef T__struct_0

typedef T__struct_0 = {
	_s:stdgo.GoString;
	_r:stdgo.GoString;
	_out:stdgo.Slice<stdgo.GoString>;
	_n:stdgo.GoInt;
};

typedef T__struct_1

typedef T__struct_1 = {
	_reFlags:stdgo.regexp.syntax.Flags;
	_expMatch:Bool;
};

typedef T__struct_2

typedef T__struct_2 = {
	_re:stdgo.GoString;
	_name:stdgo.GoString;
};

typedef T__struct_3

typedef T__struct_3 = {
	regexp:stdgo.GoString;
	_min:stdgo.GoInt;
};

typedef T__struct_4

typedef T__struct_4 = {
	_name:stdgo.GoString;
	_n:stdgo.GoInt;
};

typedef T__struct_5

typedef T__struct_5 = {
	_rightPC:stdgo.GoUInt32;
	_right:stdgo.Slice<stdgo.GoInt32>;
	_next:stdgo.Slice<stdgo.GoUInt32>;
	_merged:stdgo.Slice<stdgo.GoInt32>;
	_leftPC:stdgo.GoUInt32;
	_left:stdgo.Slice<stdgo.GoInt32>;
};

typedef T__struct_6

typedef T__struct_6 = {
	_re:stdgo.GoString;
	_isOnePass:Bool;
};

typedef T__struct_7

typedef T__struct_7 = {
	_re:stdgo.GoString;
	_match:stdgo.GoString;
};

typedef T_input

typedef T_input = {
	public function _step(_pos:stdgo.GoInt):{
		_1:stdgo.GoInt;
		_0:stdgo.GoRune;
	};	//  advance one rune
	public function _index(_re:stdgo.Ref<stdgo.regexp.Regexp>, _pos:stdgo.GoInt):stdgo.GoInt;
	public function _hasPrefix(_re:stdgo.Ref<stdgo.regexp.Regexp>):Bool;
	public function _context(_pos:stdgo.GoInt):stdgo.regexp.T_lazyFlag;
	public function _canCheckPrefix():Bool;	//  can we look ahead without losing info?
};

input abstracts different representations of the input text. It provides one-character lookahead.

typedef T_lazyFlag

typedef T_lazyFlag = stdgo.GoUInt64;

A lazyFlag is a lazily-evaluated syntax.EmptyOp, for checking zero-width flags like ^ $ \A \z \B \b. It records the pair of relevant runes and does not determine the implied flags until absolutely necessary (most of the time, that means never).

typedef T_runeSlice

typedef T_runeSlice = stdgo.Slice<stdgo.GoInt32>;

runeSlice exists to permit sorting the case-folded rune sets.