Documentation ¶
Index ¶
- Constants
- type CompileError
- type Matcher
- func (m *Matcher) Exec(subject []byte, flags int) int
- func (m *Matcher) ExecString(subject string, flags int) int
- func (m *Matcher) Extract() [][]byte
- func (m *Matcher) ExtractString() []string
- func (m *Matcher) Group(group int) []byte
- func (m *Matcher) GroupIndices(group int) []int
- func (m *Matcher) GroupString(group int) string
- func (m *Matcher) Groups() int
- func (m *Matcher) Index() (loc []int)
- func (m *Matcher) Init(re *Regexp)
- func (m *Matcher) Match(subject []byte, flags int) bool
- func (m *Matcher) MatchString(subject string, flags int) bool
- func (m *Matcher) Matches() bool
- func (m *Matcher) Named(group string) ([]byte, error)
- func (m *Matcher) NamedPresent(group string) (bool, error)
- func (m *Matcher) NamedString(group string) (string, error)
- func (m *Matcher) Partial() bool
- func (m *Matcher) Present(group int) bool
- func (m *Matcher) Reset(re Regexp, subject []byte, flags int) bool
- func (m *Matcher) ResetString(re Regexp, subject string, flags int) bool
- type Regexp
- func (re *Regexp) FindIndex(bytes []byte, flags int) (loc []int)
- func (re Regexp) Groups() int
- func (re Regexp) Matcher(subject []byte, flags int) (m *Matcher)
- func (re Regexp) MatcherString(subject string, flags int) (m *Matcher)
- func (re Regexp) NewMatcher() (m *Matcher)
- func (re Regexp) ReplaceAll(bytes, repl []byte, flags int) []byte
- func (re Regexp) ReplaceAllString(in, repl string, flags int) string
- func (re *Regexp) Study(flags int) error
Constants ¶
const ( ANCHORED = C.PCRE_ANCHORED BSR_ANYCRLF = C.PCRE_BSR_ANYCRLF BSR_UNICODE = C.PCRE_BSR_UNICODE NEWLINE_ANY = C.PCRE_NEWLINE_ANY NEWLINE_ANYCRLF = C.PCRE_NEWLINE_ANYCRLF NEWLINE_CR = C.PCRE_NEWLINE_CR NEWLINE_CRLF = C.PCRE_NEWLINE_CRLF NEWLINE_LF = C.PCRE_NEWLINE_LF NO_START_OPTIMIZE = C.PCRE_NO_START_OPTIMIZE NO_UTF8_CHECK = C.PCRE_NO_UTF8_CHECK )
Flags for Compile and Match functions.
const ( CASELESS = C.PCRE_CASELESS DOLLAR_ENDONLY = C.PCRE_DOLLAR_ENDONLY DOTALL = C.PCRE_DOTALL DUPNAMES = C.PCRE_DUPNAMES EXTENDED = C.PCRE_EXTENDED EXTRA = C.PCRE_EXTRA FIRSTLINE = C.PCRE_FIRSTLINE JAVASCRIPT_COMPAT = C.PCRE_JAVASCRIPT_COMPAT MULTILINE = C.PCRE_MULTILINE NEVER_UTF = C.PCRE_NEVER_UTF NO_AUTO_CAPTURE = C.PCRE_NO_AUTO_CAPTURE UNGREEDY = C.PCRE_UNGREEDY UTF8 = C.PCRE_UTF8 UCP = C.PCRE_UCP )
Flags for Compile functions
const ( NOTBOL = C.PCRE_NOTBOL NOTEOL = C.PCRE_NOTEOL NOTEMPTY = C.PCRE_NOTEMPTY NOTEMPTY_ATSTART = C.PCRE_NOTEMPTY_ATSTART PARTIAL_HARD = C.PCRE_PARTIAL_HARD PARTIAL_SOFT = C.PCRE_PARTIAL_SOFT )
Flags for Match functions
const ( STUDY_JIT_COMPILE = C.PCRE_STUDY_JIT_COMPILE STUDY_JIT_PARTIAL_SOFT_COMPILE = C.PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE STUDY_JIT_PARTIAL_HARD_COMPILE = C.PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE )
Flags for Study function
const ( ERROR_NOMATCH = C.PCRE_ERROR_NOMATCH ERROR_NULL = C.PCRE_ERROR_NULL ERROR_BADOPTION = C.PCRE_ERROR_BADOPTION ERROR_BADMAGIC = C.PCRE_ERROR_BADMAGIC ERROR_UNKNOWN_OPCODE = C.PCRE_ERROR_UNKNOWN_OPCODE ERROR_UNKNOWN_NODE = C.PCRE_ERROR_UNKNOWN_NODE ERROR_NOMEMORY = C.PCRE_ERROR_NOMEMORY ERROR_NOSUBSTRING = C.PCRE_ERROR_NOSUBSTRING ERROR_MATCHLIMIT = C.PCRE_ERROR_MATCHLIMIT ERROR_CALLOUT = C.PCRE_ERROR_CALLOUT ERROR_BADUTF8 = C.PCRE_ERROR_BADUTF8 ERROR_BADUTF8_OFFSET = C.PCRE_ERROR_BADUTF8_OFFSET ERROR_PARTIAL = C.PCRE_ERROR_PARTIAL ERROR_BADPARTIAL = C.PCRE_ERROR_BADPARTIAL ERROR_RECURSIONLIMIT = C.PCRE_ERROR_RECURSIONLIMIT ERROR_INTERNAL = C.PCRE_ERROR_INTERNAL ERROR_BADCOUNT = C.PCRE_ERROR_BADCOUNT ERROR_JIT_STACKLIMIT = C.PCRE_ERROR_JIT_STACKLIMIT )
Exec-time and get/set-time error codes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompileError ¶
type CompileError struct { Pattern string // The failed pattern Message string // The error message Offset int // Byte position of error }
CompileError holds details about a compilation error, as returned by the Compile function. The offset is the byte position in the pattern string at which the error was detected.
func (*CompileError) Error ¶
func (e *CompileError) Error() string
Error converts a compile error to a string
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher objects provide a place for storing match results. They can be created by the Matcher and MatcherString functions, or they can be initialized with Reset or ResetString.
func (*Matcher) Exec ¶
Exec tries to match the specified byte slice to the current pattern. Returns the raw pcre_exec error code.
func (*Matcher) ExecString ¶
ExecString tries to match the specified subject string to the current pattern. It returns the raw pcre_exec error code.
func (*Matcher) Extract ¶
Extract returns a slice of byte slices for a single match. The first byte slice contains the complete match. Subsequent byte slices contain the captured groups. If there was no match then nil is returned.
func (*Matcher) ExtractString ¶
ExtractString returns a slice of strings for a single match. The first string contains the complete match. Subsequent strings in the slice contain the captured groups. If there was no match then nil is returned.
func (*Matcher) Group ¶
Group returns the numbered capture group of the last match (performed by Matcher, MatcherString, Reset, ResetString, Match, or MatchString). Group 0 is the part of the subject which matches the whole pattern; the first actual capture group is numbered 1. Capture groups which are not present return a nil slice.
func (*Matcher) GroupIndices ¶
GroupIndices returns the numbered capture group positions of the last match (performed by Matcher, MatcherString, Reset, ResetString, Match, or MatchString). Group 0 is the part of the subject which matches the whole pattern; the first actual capture group is numbered 1. Capture groups which are not present return a nil slice.
func (*Matcher) GroupString ¶
GroupString returns the numbered capture group as a string. Group 0 is the part of the subject which matches the whole pattern; the first actual capture group is numbered 1. Capture groups which are not present return an empty string.
func (*Matcher) Index ¶
Index returns the start and end of the first match, if a previous call to Matcher, MatcherString, Reset, ResetString, Match or MatchString succeeded. loc[0] is the start and loc[1] is the end.
func (*Matcher) Match ¶
Match tries to match the specified byte slice to the current pattern by calling Exec and collects the result. Returns true if the match succeeds.
func (*Matcher) MatchString ¶
MatchString tries to match the specified subject string to the current pattern by calling ExecString and collects the result. Returns true if the match succeeds.
func (*Matcher) Matches ¶
Matches returns true if a previous call to Matcher, MatcherString, Reset, ResetString, Match or MatchString succeeded.
func (*Matcher) Named ¶
Named returns the value of the named capture group. This is a nil slice if the capture group is not present. If the name does not refer to a group then error is non-nil.
func (*Matcher) NamedPresent ¶
NamedPresent returns true if the named capture group is present. If the name does not refer to a group then error is non-nil.
func (*Matcher) NamedString ¶
NamedString returns the value of the named capture group, or an empty string if the capture group is not present. If the name does not refer to a group then error is non-nil.
func (*Matcher) Partial ¶
Partial returns true if a previous call to Matcher, MatcherString, Reset, ResetString, Match or MatchString found a partial match.
func (*Matcher) Present ¶
Present returns true if the numbered capture group is present in the last match (performed by Matcher, MatcherString, Reset, ResetString, Match, or MatchString). Group numbers start at 1. A capture group can be present and match the empty string.
type Regexp ¶
type Regexp struct {
// contains filtered or unexported fields
}
Regexp holds a reference to a compiled regular expression. Use Compile or MustCompile to create such objects.
func Compile ¶
Compile the pattern and return a compiled regexp. If compilation fails, the second return value holds a *CompileError.
func CompileJIT ¶
CompileJIT is a combination of Compile and Study. It first compiles the pattern and if this succeeds calls Study on the compiled pattern. comFlags are Compile flags, jitFlags are study flags. If compilation fails, the second return value holds a *CompileError.
func MustCompile ¶
MustCompile compiles the pattern. If compilation fails, panic.
func MustCompileJIT ¶
MustCompileJIT compiles and studies the pattern. On failure it panics.
func (*Regexp) FindIndex ¶
FindIndex returns the start and end of the first match, or nil if no match. loc[0] is the start and loc[1] is the end.
func (Regexp) Matcher ¶
Matcher creates a new matcher object, with the byte slice as subject. It also starts a first match on subject. Test for success with Matches().
func (Regexp) MatcherString ¶
MatcherString creates a new matcher, with the specified subject string. It also starts a first match on subject. Test for success with Matches().
func (Regexp) NewMatcher ¶
NewMatcher creates a new matcher object for the given Regexp.
func (Regexp) ReplaceAll ¶
ReplaceAll returns a copy of a byte slice where all pattern matches are replaced by repl.
func (Regexp) ReplaceAllString ¶
ReplaceAllString is equivalent to ReplaceAll with string return type.