亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數據結構heap) container/list(容器數據結構list) container/ring(容器數據結構ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數據庫/sql) database/sql/driver(數據庫/sql/driver) debug debug/dwarf(調試/dwarf) debug/elf(調試/elf) debug/gosym(調試/gosym) debug/macho(調試/macho) debug/pe(調試/pe) debug/plan9obj(調試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "regexp/syntax"

  • 概述

  • 索引

概述

包語法將正則表達式解析為解析樹并將解析樹編譯為程序。大多數正則表達式的客戶端將使用regexp包的工具(如編譯和匹配)而不是此包。

Syntax

使用Perl標志解析時,所了解的正則表達式語法如下所示。通過向Parse傳遞備用標志可以禁用部分語法。

單個字符:

.              any character, possibly including newline (flag s=true)[xyz]          character class[^xyz]         negated character class\d             Perl character class\D             negated Perl character class[[:alpha:]]    ASCII character class[[:^alpha:]]   negated ASCII character class\pN            Unicode character class (one-letter name)\p{Greek}      Unicode character class\PN            negated Unicode character class (one-letter name)\P{Greek}      negated Unicode character class

復合語句:

xy             x followed by y
x|y            x or y (prefer x)

重復:

x*             zero or more x, prefer more
x+             one or more x, prefer more
x?             zero or one x, prefer one
x{n,m}         n or n+1 or ... or m x, prefer more
x{n,}          n or more x, prefer more
x{n}           exactly n x
x*?            zero or more x, prefer fewer
x+?            one or more x, prefer fewer
x??            zero or one x, prefer zero
x{n,m}?        n or n+1 or ... or m x, prefer fewer
x{n,}?         n or more x, prefer fewer
x{n}?          exactly n x

實施限制:計數形式x {n,m},x {n,}和x {n}拒絕創(chuàng)建超過1000的最小或最大重復次數的表單。無限重復不受此限制。

分組:

(re)           numbered capturing group (submatch)(?P<name>re)   named & numbered capturing group (submatch)(?:re)         non-capturing group(?flags)       set flags within current group; non-capturing(?flags:re)    set flags during re; non-capturing

Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:i              case-insensitive (default false)m              multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)s              let . match \n (default false)U              ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)

空字符串:

^              at beginning of text or line (flag m=true)$              at end of text (like \z not Perl's \Z) or line (flag m=true)\A             at beginning of text
\b             at ASCII word boundary (\w on one side and \W, \A, or \z on the other)\B             not at ASCII word boundary
\z             at end of text

轉義序列:

\a             bell (== \007)\f             form feed (== \014)\t             horizontal tab (== \011)\n             newline (== \012)\r             carriage return (== \015)\v             vertical tab character (== \013)\*             literal *, for any punctuation character *\123           octal character code (up to three digits)\x7F           hex character code (exactly two digits)\x{10FFFF}     hex character code
\Q...\E        literal text ... even if ... has punctuation

字符類元素:

x              single character
A-Z            character range (inclusive)\d             Perl character class[:foo:]        ASCII character class foo\p{Foo}        Unicode character class Foo\pF            Unicode character class F (one-letter name)

將字符類命名為字符類元素:

[\d]           digits (== \d)[^\d]          not digits (== \D)[\D]           not digits (== \D)[^\D]          not not digits (== \d)[[:name:]]     named ASCII class inside character class (== [:name:])[^[:name:]]    named ASCII class inside negated character class (== [:^name:])[\p{Name}]     named Unicode property inside character class (== \p{Name})[^\p{Name}]    named Unicode property inside negated character class (== \P{Name})

Perl字符類(全部為ASCII):

\d             digits (== [0-9])\D             not digits (== [^0-9])\s             whitespace (== [\t\n\f\r ])\S             not whitespace (== [^\t\n\f\r ])\w             word characters (== [0-9A-Za-z_])\W             not word characters (== [^0-9A-Za-z_])

ASCII字符類:

[[:alnum:]]    alphanumeric (== [0-9A-Za-z])[[:alpha:]]    alphabetic (== [A-Za-z])[[:ascii:]]    ASCII (== [\x00-\x7F])[[:blank:]]    blank (== [\t ])[[:cntrl:]]    control (== [\x00-\x1F\x7F])[[:digit:]]    digits (== [0-9])[[:graph:]]    graphical (== [!-~] == [A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])
[[:lower:]]    lower case (== [a-z])
[[:print:]]    printable (== [ -~] == [ [:graph:]])
[[:punct:]]    punctuation (== [!-/:-@[-`{-~])[[:space:]]    whitespace (== [\t\n\v\f\r ])[[:upper:]]    upper case (== [A-Z])[[:word:]]     word characters (== [0-9A-Za-z_])[[:xdigit:]]   hex digit (== [0-9A-Fa-f])

索引

  • func IsWordChar(r rune) bool

  • type EmptyOp

  • func EmptyOpContext(r1, r2 rune) EmptyOp

  • type Error

  • func (e *Error) Error() string

  • type ErrorCode

  • func (e ErrorCode) String() string

  • type Flags

  • type Inst

  • func (i *Inst) MatchEmptyWidth(before rune, after rune) bool

  • func (i *Inst) MatchRune(r rune) bool

  • func (i *Inst) MatchRunePos(r rune) int

  • func (i *Inst) String() string

  • type InstOp

  • func (i InstOp) String() string

  • type Op

  • type Prog

  • func Compile(re *Regexp) (*Prog, error)

  • func (p *Prog) Prefix() (prefix string, complete bool)

  • func (p *Prog) StartCond() EmptyOp

  • func (p *Prog) String() string

  • type Regexp

  • func Parse(s string, flags Flags) (*Regexp, error)

  • func (re *Regexp) CapNames() []string

  • func (x *Regexp) Equal(y *Regexp) bool

  • func (re *Regexp) MaxCap() int

  • func (re *Regexp) Simplify() *Regexp

  • func (re *Regexp) String() string

文件包

compile.go doc.go parse.go perl_groups.go prog.go regexp.go simplify.go

func IsWordChar

func IsWordChar(r rune) bool

IsWordChar在評估\ b和\ B在零寬度報告中r是否被認為是“單詞字符”。這些斷言僅為ASCII:單詞字符為A-Za-z0-9_。

type EmptyOp

EmptyOp指定一種或多種零寬度斷言的混合。

type EmptyOp uint8
const (
        EmptyBeginLine EmptyOp = 1 << iota
        EmptyEndLine
        EmptyBeginText
        EmptyEndText
        EmptyWordBoundary
        EmptyNoWordBoundary)

func EmptyOpContext

func EmptyOpContext(r1, r2 rune) EmptyOp

EmptyOpContext返回在符號r1和r2之間的位置滿足的零寬度斷言。傳遞r1 == -1表示該位置在文本的開頭。傳遞r2 == -1表示位置在文本的末尾。

type Error

錯誤描述了解析正則表達式失敗并給出違規(guī)表達式。

type Error struct {
        Code ErrorCode
        Expr string}

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

ErrorCode描述了解析正則表達式的失敗。

type ErrorCode string
const (        // Unexpected error
        ErrInternalError ErrorCode = "regexp/syntax: internal error"        // Parse errors
        ErrInvalidCharClass      ErrorCode = "invalid character class"
        ErrInvalidCharRange      ErrorCode = "invalid character class range"
        ErrInvalidEscape         ErrorCode = "invalid escape sequence"
        ErrInvalidNamedCapture   ErrorCode = "invalid named capture"
        ErrInvalidPerlOp         ErrorCode = "invalid or unsupported Perl syntax"
        ErrInvalidRepeatOp       ErrorCode = "invalid nested repetition operator"
        ErrInvalidRepeatSize     ErrorCode = "invalid repeat count"
        ErrInvalidUTF8           ErrorCode = "invalid UTF-8"
        ErrMissingBracket        ErrorCode = "missing closing ]"
        ErrMissingParen          ErrorCode = "missing closing )"
        ErrMissingRepeatArgument ErrorCode = "missing argument to repetition operator"
        ErrTrailingBackslash     ErrorCode = "trailing backslash at end of expression"
        ErrUnexpectedParen       ErrorCode = "unexpected )")

func (ErrorCode) String

func (e ErrorCode) String() string

type Flags

標志控制解析器的行為并記錄關于正則表達式上下文的信息。

type Flags uint16
const (
        FoldCase      Flags = 1 << iota // case-insensitive match
        Literal                         // treat pattern as literal string
        ClassNL                         // allow character classes like [^a-z] and [[:space:]] to match newline
        DotNL                           // allow . to match newline
        OneLine                         // treat ^ and $ as only matching at beginning and end of text
        NonGreedy                       // make repetition operators default to non-greedy
        PerlX                           // allow Perl extensions
        UnicodeGroups                   // allow \p{Han}, \P{Han} for Unicode group and negation
        WasDollar                       // regexp OpEndText was $, not \z
        Simple                          // regexp contains no counted repetition

        MatchNL = ClassNL | DotNL

        Perl        = ClassNL | OneLine | PerlX | UnicodeGroups // as close to Perl as possible
        POSIX Flags = 0                                         // POSIX syntax)

type Inst

Inst是正則表達式程序中的單個指令。

type Inst struct {
        Op   InstOp
        Out  uint32 // all but InstMatch, InstFail
        Arg  uint32 // InstAlt, InstAltMatch, InstCapture, InstEmptyWidth
        Rune []rune}

func (*Inst) MatchEmptyWidth

func (i *Inst) MatchEmptyWidth(before rune, after rune) bool

MatchEmptyWidth報告指令是否匹配符文之前和之后的空字符串。只應在i.Op == InstEmptyWidth時調用它。

func (*Inst) MatchRune

func (i *Inst) MatchRune(r rune) bool

MatchRune報告指令是否匹配(并消耗)r。它應該只在i.Op == InstRune時被調用。

func (*Inst) MatchRunePos

func (i *Inst) MatchRunePos(r rune) int

MatchRunePos檢查指令是否匹配(并消耗)r。如果是這樣,MatchRunePos返回匹配符文對的索引(或者,當len(i.Rune)== 1時,符文單例)。如果不是,則MatchRunePos返回-1。MatchRunePos只應在i.Op == InstRune時調用。

func (*Inst) String

func (i *Inst) String() string

type InstOp

InstOp是一個指令操作碼。

type InstOp uint8
const (
        InstAlt InstOp = iota
        InstAltMatch
        InstCapture
        InstEmptyWidth
        InstMatch
        InstFail
        InstNop
        InstRune
        InstRune1
        InstRuneAny
        InstRuneAnyNotNL)

func (InstOp) String

func (i InstOp) String() string

type Op

Op是單一的正則表達式運算符。

type Op uint8
const (
        OpNoMatch        Op = 1 + iota // matches no strings
        OpEmptyMatch                   // matches empty string
        OpLiteral                      // matches Runes sequence
        OpCharClass                    // matches Runes interpreted as range pair list
        OpAnyCharNotNL                 // matches any character except newline
        OpAnyChar                      // matches any character
        OpBeginLine                    // matches empty string at beginning of line
        OpEndLine                      // matches empty string at end of line
        OpBeginText                    // matches empty string at beginning of text
        OpEndText                      // matches empty string at end of text
        OpWordBoundary                 // matches word boundary `\b`
        OpNoWordBoundary               // matches word non-boundary `\B`
        OpCapture                      // capturing subexpression with index Cap, optional name Name
        OpStar                         // matches Sub[0] zero or more times
        OpPlus                         // matches Sub[0] one or more times
        OpQuest                        // matches Sub[0] zero or one times
        OpRepeat                       // matches Sub[0] at least Min times, at most Max (Max == -1 is no limit)
        OpConcat                       // matches concatenation of Subs
        OpAlternate                    // matches alternation of Subs)

type Prog

Prog是編譯的正則表達式程序。

type Prog struct {
        Inst   []Inst
        Start  int // index of start instruction
        NumCap int // number of InstCapture insts in re}

func Compile

func Compile(re *Regexp) (*Prog, error)

編譯將regexp編譯成要執(zhí)行的程序。正則表達式應該已經被簡化了(從re.Simplify返回)。

func (*Prog) Prefix

func (p *Prog) Prefix() (prefix string, complete bool)

前綴返回所有匹配的正則表達式必須以字符串開頭的文字字符串。如果前綴是整個匹配,則結果為真。

func (*Prog) StartCond

func (p *Prog) StartCond() EmptyOp

StartCond返回在任何匹配中必須為true的前導空白條件。如果不可能匹配,它返回^ EmptyOp(0)。

func (*Prog) String

func (p *Prog) String() string

type Regexp

正則表達式是正則表達式語法樹中的一個節(jié)點。

type Regexp struct {
        Op       Op // operator
        Flags    Flags
        Sub      []*Regexp  // subexpressions, if any
        Sub0     [1]*Regexp // storage for short Sub
        Rune     []rune     // matched runes, for OpLiteral, OpCharClass
        Rune0    [2]rune    // storage for short Rune
        Min, Max int        // min, max for OpRepeat
        Cap      int        // capturing index, for OpCapture
        Name     string     // capturing name, for OpCapture}

func Parse

func Parse(s string, flags Flags) (*Regexp, error)

解析由指定標志控制的正則表達式字符串s,并返回正則表達式解析樹。該語法在頂級注釋中進行了描述。

func (*Regexp) CapNames

func (re *Regexp) CapNames() []string

CapNames使用正則表達式查找捕獲組的名稱。

func (*Regexp) Equal

func (x *Regexp) Equal(y *Regexp) bool

如果x和y具有相同的結構,則相等返回true。

func (*Regexp) MaxCap

func (re *Regexp) MaxCap() int

MaxCap使用正則表達式查找最大捕獲索引。

func (*Regexp) Simplify

func (re *Regexp) Simplify() *Regexp

簡化返回相當于re的regexp,但不需要重復計算和其他各種簡化,例如重寫/(?: a +)+ / to / a + /。生成的正則表達式將正確執(zhí)行,但其字符串表示形式不會生成相同的分析樹,因為捕獲的括號可能已被復制或刪除。例如,/(x){1,2} /的簡化形式是/(x)(x)?/但兩個圓括號都捕獲為$ 1。返回的正則表達式可能與原始結構共享或成為原始結構。

func (*Regexp) String

func (re *Regexp) String() string
Previous article: Next article: