package syntax

Import Path
	regexp/syntax (on and

Dependency Relation
	imports 5 packages, and imported by one package

Involved Source Files
	d-> doc.go

Exported Type Names

type EmptyOp uint8 An EmptyOp specifies a kind or mixture of zero-width assertions. func EmptyOpContext(r1, r2 rune) EmptyOp func (*Prog).StartCond() EmptyOp const EmptyBeginLine const EmptyBeginText const EmptyEndLine const EmptyEndText const EmptyNoWordBoundary const EmptyWordBoundary
type Error (struct) An Error describes a failure to parse a regular expression and gives the offending expression. Code ErrorCode Expr string (*T) Error() string *T : error
type ErrorCode string An ErrorCode describes a failure to parse a regular expression. ( T) String() string T : expvar.Var T : fmt.Stringer const ErrInternalError const ErrInvalidCharClass const ErrInvalidCharRange const ErrInvalidEscape const ErrInvalidNamedCapture const ErrInvalidPerlOp const ErrInvalidRepeatOp const ErrInvalidRepeatSize const ErrInvalidUTF8 const ErrMissingBracket const ErrMissingParen const ErrMissingRepeatArgument const ErrTrailingBackslash const ErrUnexpectedParen
type Flags uint16 Flags control the behavior of the parser and record information about regexp context. func Parse(s string, flags Flags) (*Regexp, error) const ClassNL const DotNL const FoldCase const Literal const MatchNL const NonGreedy const OneLine const Perl const PerlX const POSIX const Simple const UnicodeGroups const WasDollar
type Inst (struct) An Inst is a single instruction in a regular expression program. // InstAlt, InstAltMatch, InstCapture, InstEmptyWidth Op InstOp // all but InstMatch, InstFail Rune []rune MatchEmptyWidth reports whether the instruction matches an empty string between the runes before and after. It should only be called when i.Op == InstEmptyWidth. MatchRune reports whether the instruction matches (and consumes) r. It should only be called when i.Op == InstRune. MatchRunePos checks whether the instruction matches (and consumes) r. If so, MatchRunePos returns the index of the matching rune pair (or, when len(i.Rune) == 1, rune singleton). If not, MatchRunePos returns -1. MatchRunePos should only be called when i.Op == InstRune. (*T) String() string *T : expvar.Var *T : fmt.Stringer
type InstOp uint8 An InstOp is an instruction opcode. ( T) String() string T : expvar.Var T : fmt.Stringer const InstAlt const InstAltMatch const InstCapture const InstEmptyWidth const InstFail const InstMatch const InstNop const InstRune const InstRune1 const InstRuneAny const InstRuneAnyNotNL
type Op uint8 An Op is a single regular expression operator. ( T) String() string T : expvar.Var T : fmt.Stringer const OpAlternate const OpAnyChar const OpAnyCharNotNL const OpBeginLine const OpBeginText const OpCapture const OpCharClass const OpConcat const OpEmptyMatch const OpEndLine const OpEndText const OpLiteral const OpNoMatch const OpNoWordBoundary const OpPlus const OpQuest const OpRepeat const OpStar const OpWordBoundary
type Prog (struct) A Prog is a compiled regular expression program. Inst []Inst // number of InstCapture insts in re // index of start instruction Prefix returns a literal string that all matches for the regexp must start with. Complete is true if the prefix is the entire match. StartCond returns the leading empty-width conditions that must be true in any match. It returns ^EmptyOp(0) if no matches are possible. (*T) String() string *T : expvar.Var *T : fmt.Stringer func Compile(re *Regexp) (*Prog, error)
type Regexp (struct) A Regexp is a node in a regular expression syntax tree. // capturing index, for OpCapture Flags Flags // min, max for OpRepeat // min, max for OpRepeat // capturing name, for OpCapture // operator // matched runes, for OpLiteral, OpCharClass // storage for short Rune // subexpressions, if any // storage for short Sub CapNames walks the regexp to find the names of capturing groups. Equal reports whether x and y have identical structure. MaxCap walks the regexp to find the maximum capture index. Simplify returns a regexp equivalent to re but without counted repetitions and with various other simplifications, such as rewriting /(?:a+)+/ to /a+/. The resulting regexp will execute correctly but its string representation will not produce the same parse tree, because capturing parentheses may have been duplicated or removed. For example, the simplified form for /(x){1,2}/ is /(x)(x)?/ but both parentheses capture as $1. The returned regexp may share structure with or be the original. (*T) String() string *T : expvar.Var *T : fmt.Stringer func Parse(s string, flags Flags) (*Regexp, error) func (*Regexp).Simplify() *Regexp func Compile(re *Regexp) (*Prog, error) func (*Regexp).Equal(y *Regexp) bool
Exported Values
const ClassNL Flags = 4 // allow character classes like [^a-z] and [[:space:]] to match newline
func Compile(re *Regexp) (*Prog, error) Compile compiles the regexp into a program to be executed. The regexp should have been simplified already (returned from re.Simplify).
const DotNL Flags = 8 // allow . to match newline
func EmptyOpContext(r1, r2 rune) EmptyOp EmptyOpContext returns the zero-width assertions satisfied at the position between the runes r1 and r2. Passing r1 == -1 indicates that the position is at the beginning of the text. Passing r2 == -1 indicates that the position is at the end of the text.
const ErrInternalError ErrorCode = "regexp/syntax: internal error" Unexpected error
const ErrInvalidCharClass ErrorCode = "invalid character class" Parse errors
const ErrInvalidCharRange ErrorCode = "invalid character class range"
const ErrInvalidEscape ErrorCode = "invalid escape sequence"
const ErrInvalidNamedCapture ErrorCode = "invalid named capture"
const ErrInvalidPerlOp ErrorCode = "invalid or unsupported Perl syntax"
const ErrInvalidRepeatOp ErrorCode = "invalid nested repetition operator"
const ErrInvalidRepeatSize ErrorCode = "invalid repeat count"
const ErrInvalidUTF8 ErrorCode = "invalid UTF-8"
const ErrMissingBracket ErrorCode = "missing closing ]"
const ErrMissingParen ErrorCode = "missing closing )"
const ErrMissingRepeatArgument ErrorCode = "missing argument to repetition operator"
const ErrTrailingBackslash ErrorCode = "trailing backslash at end of expression"
const ErrUnexpectedParen ErrorCode = "unexpected )"
const FoldCase Flags = 1 // case-insensitive match
const InstAlt InstOp = 0
const InstAltMatch InstOp = 1
const InstCapture InstOp = 2
const InstFail InstOp = 5
const InstMatch InstOp = 4
const InstNop InstOp = 6
const InstRune InstOp = 7
const InstRune1 InstOp = 8
const InstRuneAny InstOp = 9
func IsWordChar(r rune) bool IsWordChar reports whether r is consider a ``word character'' during the evaluation of the \b and \B zero-width assertions. These assertions are ASCII-only: the word characters are [A-Za-z0-9_].
const Literal Flags = 2 // treat pattern as literal string
const MatchNL Flags = 12
const NonGreedy Flags = 32 // make repetition operators default to non-greedy
const OneLine Flags = 16 // treat ^ and $ as only matching at beginning and end of text
const OpAlternate Op = 19 // matches alternation of Subs
const OpAnyChar Op = 6 // matches any character
const OpAnyCharNotNL Op = 5 // matches any character except newline
const OpBeginLine Op = 7 // matches empty string at beginning of line
const OpBeginText Op = 9 // matches empty string at beginning of text
const OpCapture Op = 13 // capturing subexpression with index Cap, optional name Name
const OpCharClass Op = 4 // matches Runes interpreted as range pair list
const OpConcat Op = 18 // matches concatenation of Subs
const OpEmptyMatch Op = 2 // matches empty string
const OpEndLine Op = 8 // matches empty string at end of line
const OpEndText Op = 10 // matches empty string at end of text
const OpLiteral Op = 3 // matches Runes sequence
const OpNoMatch Op = 1 // matches no strings
const OpNoWordBoundary Op = 12 // matches word non-boundary `\B`
const OpPlus Op = 15 // matches Sub[0] one or more times
const OpQuest Op = 16 // matches Sub[0] zero or one times
const OpRepeat Op = 17 // matches Sub[0] at least Min times, at most Max (Max == -1 is no limit)
const OpStar Op = 14 // matches Sub[0] zero or more times
const OpWordBoundary Op = 11 // matches word boundary `\b`
func Parse(s string, flags Flags) (*Regexp, error) Parse parses a regular expression string s, controlled by the specified Flags, and returns a regular expression parse tree. The syntax is described in the top-level comment.
const Perl Flags = 212 // as close to Perl as possible
const PerlX Flags = 64 // allow Perl extensions
const POSIX Flags = 0 // POSIX syntax
const Simple Flags = 512 // regexp contains no counted repetition
const UnicodeGroups Flags = 128 // allow \p{Han}, \P{Han} for Unicode group and negation
const WasDollar Flags = 256 // regexp OpEndText was $, not \z