Documentation
¶
Overview ¶
This package provides access to the Perl Compatible Regular Expresion library, PCRE.
It implements two main types, Regexp and Matcher. Regexp objects store a compiled regular expression. They are immutable. Compilation of regular expressions using Compile or MustCompile is slightly expensive, so these objects should be kept and reused, instead of compiling them from scratch for each matching attempt.
Matcher objects keeps the results of a match against a []byte or string subject. The Group and GroupString functions provide access to capture groups; both versions work no matter if the subject was a []byte or string, but the version with the matching type is slightly more efficient.
Matcher objects contain some temporary space and refer the original subject. They are mutable and can be reused (using Match, MatchString, Reset or ResetString).
For details on the regular expression language implemented by this package and the flags defined below, see the PCRE documentation.
Index ¶
- Constants
- Variables
- func PcreppReplaceImpl(pattern string, repl string, src string) string
- func Pcrepp_Replace(arg1 string, arg2 string, arg3 string) (_swig_ret string)
- func Swig_free(arg1 uintptr)
- func Swig_malloc(arg1 int) (_swig_ret uintptr)
- type CompileError
- type Matcher
- func (m *Matcher) Group(group int) []byte
- func (m *Matcher) GroupString(group int) string
- func (m *Matcher) Groups() int
- 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
- func (m *Matcher) NamedPresent(group string) bool
- func (m *Matcher) NamedString(group string) string
- func (m *Matcher) Present(group int) bool
- func (m *Matcher) Reset(re Regexp, subject []byte, flags int)
- func (m *Matcher) ResetString(re Regexp, subject string, flags int)
- type Regexp
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_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 NO_AUTO_CAPTURE = C.PCRE_NO_AUTO_CAPTURE UNGREEDY = C.PCRE_UNGREEDY UTF8 = C.PCRE_UTF8 )
Flags for Compile functions
const ( NOTBOL = C.PCRE_NOTBOL NOTEOL = C.PCRE_NOTEOL NOTEMPTY = C.PCRE_NOTEMPTY NOTEMPTY_ATSTART = C.PCRE_NOTEMPTY_ATSTART NO_START_OPTIMIZE = C.PCRE_NO_START_OPTIMIZE PARTIAL_HARD = C.PCRE_PARTIAL_HARD PARTIAL_SOFT = C.PCRE_PARTIAL_SOFT )
Flags for Match functions
Variables ¶
var Swig_escape_always_false bool
var Swig_escape_val interface{}
Functions ¶
func PcreppReplaceImpl ¶ added in v1.0.5
func Pcrepp_Replace ¶ added in v1.0.5
func Swig_malloc ¶ added in v1.0.5
Types ¶
type CompileError ¶
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
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) 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) 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) Match ¶
Tries to match the speficied byte array slice to the current pattern. Returns true if the match succeeds.
func (*Matcher) MatchString ¶
Tries to match the speficied subject string to the current pattern. Returns true if the match succeeds.
func (*Matcher) Matches ¶
Returns true if a previous call to Matcher, MatcherString, Reset, ResetString, Match or MatchString succeeded.
func (*Matcher) Named ¶
Returns the value of the named capture group. This is a nil slice if the capture group is not present. Panics if the name does not refer to a group.
func (*Matcher) NamedPresent ¶
Returns true if the named capture group is present. Panics if the name does not refer to a group.
func (*Matcher) NamedString ¶
Returns the value of the named capture group, or an empty string if the capture group is not present. Panics if the name does not refer to a group.
func (*Matcher) 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
}
A reference to a compiled regular expression. Use Compile or MustCompile to create such objects.
func MustCompile ¶
Compile the pattern. If compilation fails, panic.
func (*Regexp) FindIndex ¶
Return the start and end of the first match, or nil if no match. loc[0] is the start and loc[1] is the end.