Documentation ¶
Index ¶
- Constants
- Variables
- func ConfigAll() (ret string)
- func TestCaseless()
- func TestCompile()
- func TestCompileFail()
- func TestExtract()
- func TestExtractString()
- func TestFindIndex()
- func TestMatcher()
- func TestNamed()
- func TestPartial()
- func TestReplaceAll()
- type CompileError
- type JITError
- type MatchError
- type Matcher
- func (m *Matcher) Exec(subject []byte, flags uint32) int
- func (m *Matcher) Extract() [][]byte
- func (m *Matcher) ExtractString() []string
- func (m *Matcher) Free()
- func (m *Matcher) GetError() error
- func (m *Matcher) Group(group int) []byte
- func (m *Matcher) GroupIndices(group int) []int
- func (m *Matcher) HasError() bool
- func (m *Matcher) Index() (loc []int)
- func (m *Matcher) Init(re *Regexp)
- func (m *Matcher) Match(subject []byte, flags uint32) bool
- func (m *Matcher) Named(group string) ([]byte, error)
- func (m *Matcher) NamedPresent(group string) bool
- func (m *Matcher) Present(group int) bool
- func (m *Matcher) Reset(re *Regexp, subject []byte, flags uint32) bool
- type Regexp
- func (re *Regexp) FindAllIndex(bytes []byte, flags uint32) (r [][]int)
- func (re *Regexp) FindIndex(bytes []byte, flags uint32) (loc []int)
- func (re *Regexp) Free() error
- func (re *Regexp) Groups() int
- func (re *Regexp) JITCompile(flags uint32) error
- func (re *Regexp) Matcher(subject []byte, flags uint32) (m *Matcher)
- func (re *Regexp) NewMatcher() (m *Matcher)
- func (re *Regexp) ReplaceAll(bytes, repl []byte, flags uint32) []byte
Constants ¶
const ( ANCHORED = C.PCRE2_ANCHORED NO_UTF_CHECK = C.PCRE2_NO_UTF_CHECK ENDANCHORED = C.PCRE2_ENDANCHORED )
The following option bits can be passed to Compile(), Match(), or DfaMatch(). NO_UTF_CHECK affects only the function to which it is passed. Put these bits at the most significant end of the options word so others can be added next to them.
const ( ALLOW_EMPTY_CLASS = C.PCRE2_ALLOW_EMPTY_CLASS /* C */ ALT_BSUX = C.PCRE2_ALT_BSUX /* C */ AUTO_CALLOUT = C.PCRE2_AUTO_CALLOUT /* C */ CASELESS = C.PCRE2_CASELESS /* C */ DOLLAR_ENDONLY = C.PCRE2_DOLLAR_ENDONLY /* J M D */ DOTALL = C.PCRE2_DOTALL /* C */ DUPNAMES = C.PCRE2_DUPNAMES /* C */ EXTENDED = C.PCRE2_EXTENDED /* C */ FIRSTLINE = C.PCRE2_FIRSTLINE /* J M D */ MATCH_UNSET_BACKREF = C.PCRE2_MATCH_UNSET_BACKREF /* C J M */ MULTILINE = C.PCRE2_MULTILINE /* C */ NEVER_UCP = C.PCRE2_NEVER_UCP /* C */ NEVER_UTF = C.PCRE2_NEVER_UTF /* C */ NO_AUTO_CAPTURE = C.PCRE2_NO_AUTO_CAPTURE /* C */ NO_AUTO_POSSESS = C.PCRE2_NO_AUTO_POSSESS /* C */ NO_DOTSTAR_ANCHOR = C.PCRE2_NO_DOTSTAR_ANCHOR /* C */ NO_START_OPTIMIZE = C.PCRE2_NO_START_OPTIMIZE /* J M D */ UCP = C.PCRE2_UCP /* C J M D */ UNGREEDY = C.PCRE2_UNGREEDY /* C */ UTF = C.PCRE2_UTF /* C J M D */ NEVER_BACKSLASH_C = C.PCRE2_NEVER_BACKSLASH_C /* C */ ALT_CIRCUMFLEX = C.PCRE2_ALT_CIRCUMFLEX /* J M D */ ALT_VERBNAMES = C.PCRE2_ALT_VERBNAMES /* C */ USE_OFFSET_LIMIT = C.PCRE2_USE_OFFSET_LIMIT /* J M D */ EXTENDED_MORE = C.PCRE2_EXTENDED_MORE /* C */ LITERAL = C.PCRE2_LITERAL /* C */ )
The following option bits can be passed only to Compile(). However, they may affect compilation, JIT compilation, and/or interpretive execution. The following tags indicate which:
C alters what is compiled by pcre2_compile() J alters what is compiled by pcre2_jit_compile() M is inspected during pcre2_match() execution D is inspected during pcre2_dfa_match() execution
const ( EXTRA_ALLOW_SURROGATE_ESCAPES = C.PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES /* C */ EXTRA_BAD_ESCAPE_IS_LITERAL = C.PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL /* C */ EXTRA_MATCH_WORD = C.PCRE2_EXTRA_MATCH_WORD /* C */ EXTRA_MATCH_LINE = C.PCRE2_EXTRA_MATCH_LINE /* C */ )
An additional compile options word is available in the compile context.
const ( JIT_COMPLETE = C.PCRE2_JIT_COMPLETE /* For full matching */ JIT_PARTIAL_SOFT = C.PCRE2_JIT_PARTIAL_SOFT JIT_PARTIAL_HARD = C.PCRE2_JIT_PARTIAL_HARD )
These are for JITCompile()
const ( NOTBOL = C.PCRE2_NOTBOL NOTEOL = C.PCRE2_NOTEOL NOTEMPTY = C.PCRE2_NOTEMPTY /* ) These two must be kept */ NOTEMPTY_ATSTART = C.PCRE2_NOTEMPTY_ATSTART /* ) adjacent to each other. */ PARTIAL_SOFT = C.PCRE2_PARTIAL_SOFT PARTIAL_HARD = C.PCRE2_PARTIAL_HARD )
These are for Match() and DfaMatch(). Note that ANCHORED, and NO_UTF_CHECK can also be passed to these functions, so take care not to define synonyms by mistake.
const ( DFA_RESTART = C.PCRE2_DFA_RESTART DFA_SHORTEST = C.PCRE2_DFA_SHORTEST )
These are additional options for DfaMatch().
const ( SUBSTITUTE_GLOBAL = C.PCRE2_SUBSTITUTE_GLOBAL SUBSTITUTE_EXTENDED = C.PCRE2_SUBSTITUTE_EXTENDED SUBSTITUTE_UNSET_EMPTY = C.PCRE2_SUBSTITUTE_UNSET_EMPTY SUBSTITUTE_UNKNOWN_UNSET = C.PCRE2_SUBSTITUTE_UNKNOWN_UNSET SUBSTITUTE_OVERFLOW_LENGTH = C.PCRE2_SUBSTITUTE_OVERFLOW_LENGTH )
These are additional options for Substitute(), which passes any others through to Match().
const ( CONVERT_UTF = C.PCRE2_CONVERT_UTF CONVERT_NO_UTF_CHECK = C.PCRE2_CONVERT_NO_UTF_CHECK CONVERT_POSIX_BASIC = C.PCRE2_CONVERT_POSIX_BASIC CONVERT_POSIX_EXTENDED = C.PCRE2_CONVERT_POSIX_EXTENDED CONVERT_GLOB = C.PCRE2_CONVERT_GLOB CONVERT_GLOB_NO_WILD_SEPARATOR = C.PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR CONVERT_GLOB_NO_STARSTAR = C.PCRE2_CONVERT_GLOB_NO_STARSTAR )
Options for pcre2_pattern_convert().
const ( NEWLINE_CR = C.PCRE2_NEWLINE_CR NEWLINE_LF = C.PCRE2_NEWLINE_LF NEWLINE_CRLF = C.PCRE2_NEWLINE_CRLF NEWLINE_ANY = C.PCRE2_NEWLINE_ANY NEWLINE_ANYCRLF = C.PCRE2_NEWLINE_ANYCRLF NEWLINE_NUL = C.PCRE2_NEWLINE_NUL BSR_UNICODE = C.PCRE2_BSR_UNICODE BSR_ANYCRLF = C.PCRE2_BSR_ANYCRLF )
Newline and \R settings, for use in compile contexts. The newline values must be kept in step with values set in config.h and both sets must all be greater than zero.
const ( ERROR_END_BACKSLASH = C.PCRE2_ERROR_END_BACKSLASH ERROR_END_BACKSLASH_C = C.PCRE2_ERROR_END_BACKSLASH_C ERROR_UNKNOWN_ESCAPE = C.PCRE2_ERROR_UNKNOWN_ESCAPE ERROR_QUANTIFIER_OUT_OF_ORDER = C.PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER ERROR_QUANTIFIER_TOO_BIG = C.PCRE2_ERROR_QUANTIFIER_TOO_BIG ERROR_MISSING_SQUARE_BRACKET = C.PCRE2_ERROR_MISSING_SQUARE_BRACKET ERROR_ESCAPE_INVALID_IN_CLASS = C.PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS ERROR_CLASS_RANGE_ORDER = C.PCRE2_ERROR_CLASS_RANGE_ORDER ERROR_QUANTIFIER_INVALID = C.PCRE2_ERROR_QUANTIFIER_INVALID ERROR_INTERNAL_UNEXPECTED_REPEAT = C.PCRE2_ERROR_INTERNAL_UNEXPECTED_REPEAT ERROR_INVALID_AFTER_PARENS_QUERY = C.PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY ERROR_POSIX_CLASS_NOT_IN_CLASS = C.PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS ERROR_POSIX_NO_SUPPORT_COLLATING = C.PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING ERROR_MISSING_CLOSING_PARENTHESIS = C.PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS ERROR_BAD_SUBPATTERN_REFERENCE = C.PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE ERROR_NULL_PATTERN = C.PCRE2_ERROR_NULL_PATTERN ERROR_BAD_OPTIONS = C.PCRE2_ERROR_BAD_OPTIONS ERROR_MISSING_COMMENT_CLOSING = C.PCRE2_ERROR_MISSING_COMMENT_CLOSING ERROR_PARENTHESES_NEST_TOO_DEEP = C.PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP ERROR_PATTERN_TOO_LARGE = C.PCRE2_ERROR_PATTERN_TOO_LARGE ERROR_HEAP_FAILED = C.PCRE2_ERROR_HEAP_FAILED ERROR_UNMATCHED_CLOSING_PARENTHESIS = C.PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS ERROR_INTERNAL_CODE_OVERFLOW = C.PCRE2_ERROR_INTERNAL_CODE_OVERFLOW ERROR_MISSING_CONDITION_CLOSING = C.PCRE2_ERROR_MISSING_CONDITION_CLOSING ERROR_LOOKBEHIND_NOT_FIXED_LENGTH = C.PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH ERROR_ZERO_RELATIVE_REFERENCE = C.PCRE2_ERROR_ZERO_RELATIVE_REFERENCE ERROR_TOO_MANY_CONDITION_BRANCHES = C.PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES ERROR_CONDITION_ASSERTION_EXPECTED = C.PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED ERROR_BAD_RELATIVE_REFERENCE = C.PCRE2_ERROR_BAD_RELATIVE_REFERENCE ERROR_UNKNOWN_POSIX_CLASS = C.PCRE2_ERROR_UNKNOWN_POSIX_CLASS ERROR_INTERNAL_STUDY_ERROR = C.PCRE2_ERROR_INTERNAL_STUDY_ERROR ERROR_UNICODE_NOT_SUPPORTED = C.PCRE2_ERROR_UNICODE_NOT_SUPPORTED ERROR_PARENTHESES_STACK_CHECK = C.PCRE2_ERROR_PARENTHESES_STACK_CHECK ERROR_CODE_POINT_TOO_BIG = C.PCRE2_ERROR_CODE_POINT_TOO_BIG ERROR_LOOKBEHIND_TOO_COMPLICATED = C.PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED ERROR_LOOKBEHIND_INVALID_BACKSLASH_C = C.PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C ERROR_UNSUPPORTED_ESCAPE_SEQUENCE = C.PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE ERROR_CALLOUT_NUMBER_TOO_BIG = C.PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG ERROR_MISSING_CALLOUT_CLOSING = C.PCRE2_ERROR_MISSING_CALLOUT_CLOSING ERROR_ESCAPE_INVALID_IN_VERB = C.PCRE2_ERROR_ESCAPE_INVALID_IN_VERB ERROR_UNRECOGNIZED_AFTER_QUERY_P = C.PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P ERROR_MISSING_NAME_TERMINATOR = C.PCRE2_ERROR_MISSING_NAME_TERMINATOR ERROR_DUPLICATE_SUBPATTERN_NAME = C.PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME ERROR_INVALID_SUBPATTERN_NAME = C.PCRE2_ERROR_INVALID_SUBPATTERN_NAME ERROR_UNICODE_PROPERTIES_UNAVAILABLE = C.PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE ERROR_MALFORMED_UNICODE_PROPERTY = C.PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY ERROR_UNKNOWN_UNICODE_PROPERTY = C.PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY ERROR_SUBPATTERN_NAME_TOO_LONG = C.PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG ERROR_TOO_MANY_NAMED_SUBPATTERNS = C.PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS ERROR_CLASS_INVALID_RANGE = C.PCRE2_ERROR_CLASS_INVALID_RANGE ERROR_OCTAL_BYTE_TOO_BIG = C.PCRE2_ERROR_OCTAL_BYTE_TOO_BIG ERROR_INTERNAL_OVERRAN_WORKSPACE = C.PCRE2_ERROR_INTERNAL_OVERRAN_WORKSPACE ERROR_INTERNAL_MISSING_SUBPATTERN = C.PCRE2_ERROR_INTERNAL_MISSING_SUBPATTERN ERROR_DEFINE_TOO_MANY_BRANCHES = C.PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES ERROR_BACKSLASH_O_MISSING_BRACE = C.PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE ERROR_INTERNAL_UNKNOWN_NEWLINE = C.PCRE2_ERROR_INTERNAL_UNKNOWN_NEWLINE ERROR_BACKSLASH_G_SYNTAX = C.PCRE2_ERROR_BACKSLASH_G_SYNTAX ERROR_PARENS_QUERY_R_MISSING_CLOSING = C.PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING /* Error 159 is obsolete and should now never occur */ ERROR_VERB_ARGUMENT_NOT_ALLOWED = C.PCRE2_ERROR_VERB_ARGUMENT_NOT_ALLOWED ERROR_VERB_UNKNOWN = C.PCRE2_ERROR_VERB_UNKNOWN ERROR_SUBPATTERN_NUMBER_TOO_BIG = C.PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG ERROR_SUBPATTERN_NAME_EXPECTED = C.PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED ERROR_INTERNAL_PARSED_OVERFLOW = C.PCRE2_ERROR_INTERNAL_PARSED_OVERFLOW ERROR_INVALID_OCTAL = C.PCRE2_ERROR_INVALID_OCTAL ERROR_SUBPATTERN_NAMES_MISMATCH = C.PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH ERROR_MARK_MISSING_ARGUMENT = C.PCRE2_ERROR_MARK_MISSING_ARGUMENT ERROR_INVALID_HEXADECIMAL = C.PCRE2_ERROR_INVALID_HEXADECIMAL ERROR_BACKSLASH_C_SYNTAX = C.PCRE2_ERROR_BACKSLASH_C_SYNTAX ERROR_BACKSLASH_K_SYNTAX = C.PCRE2_ERROR_BACKSLASH_K_SYNTAX ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS = C.PCRE2_ERROR_INTERNAL_BAD_CODE_LOOKBEHINDS ERROR_BACKSLASH_N_IN_CLASS = C.PCRE2_ERROR_BACKSLASH_N_IN_CLASS ERROR_CALLOUT_STRING_TOO_LONG = C.PCRE2_ERROR_CALLOUT_STRING_TOO_LONG ERROR_UNICODE_DISALLOWED_CODE_POINT = C.PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT ERROR_UTF_IS_DISABLED = C.PCRE2_ERROR_UTF_IS_DISABLED ERROR_UCP_IS_DISABLED = C.PCRE2_ERROR_UCP_IS_DISABLED ERROR_VERB_NAME_TOO_LONG = C.PCRE2_ERROR_VERB_NAME_TOO_LONG ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG = C.PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG ERROR_MISSING_OCTAL_OR_HEX_DIGITS = C.PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS ERROR_VERSION_CONDITION_SYNTAX = C.PCRE2_ERROR_VERSION_CONDITION_SYNTAX ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS = C.PCRE2_ERROR_INTERNAL_BAD_CODE_AUTO_POSSESS ERROR_CALLOUT_NO_STRING_DELIMITER = C.PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER ERROR_CALLOUT_BAD_STRING_DELIMITER = C.PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER ERROR_BACKSLASH_C_CALLER_DISABLED = C.PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED ERROR_QUERY_BARJX_NEST_TOO_DEEP = C.PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP ERROR_BACKSLASH_C_LIBRARY_DISABLED = C.PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED ERROR_PATTERN_TOO_COMPLICATED = C.PCRE2_ERROR_PATTERN_TOO_COMPLICATED ERROR_LOOKBEHIND_TOO_LONG = C.PCRE2_ERROR_LOOKBEHIND_TOO_LONG ERROR_PATTERN_STRING_TOO_LONG = C.PCRE2_ERROR_PATTERN_STRING_TOO_LONG ERROR_INTERNAL_BAD_CODE = C.PCRE2_ERROR_INTERNAL_BAD_CODE ERROR_INTERNAL_BAD_CODE_IN_SKIP = C.PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP ERROR_NO_SURROGATES_IN_UTF16 = C.PCRE2_ERROR_NO_SURROGATES_IN_UTF16 ERROR_BAD_LITERAL_OPTIONS = C.PCRE2_ERROR_BAD_LITERAL_OPTIONS ERROR_SUPPORTED_ONLY_IN_UNICODE = C.PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE ERROR_INVALID_HYPHEN_IN_OPTIONS = C.PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS )
Error codes for Compile(). Some of these are also used by PatternConvert().
const ( ERROR_NOMATCH = C.PCRE2_ERROR_NOMATCH ERROR_PARTIAL = C.PCRE2_ERROR_PARTIAL )
"Expected" matching error codes: no match and partial match.
const ( ERROR_UTF8_ERR1 = C.PCRE2_ERROR_UTF8_ERR1 ERROR_UTF8_ERR2 = C.PCRE2_ERROR_UTF8_ERR2 ERROR_UTF8_ERR3 = C.PCRE2_ERROR_UTF8_ERR3 ERROR_UTF8_ERR4 = C.PCRE2_ERROR_UTF8_ERR4 ERROR_UTF8_ERR5 = C.PCRE2_ERROR_UTF8_ERR5 ERROR_UTF8_ERR6 = C.PCRE2_ERROR_UTF8_ERR6 ERROR_UTF8_ERR7 = C.PCRE2_ERROR_UTF8_ERR7 ERROR_UTF8_ERR8 = C.PCRE2_ERROR_UTF8_ERR8 ERROR_UTF8_ERR9 = C.PCRE2_ERROR_UTF8_ERR9 ERROR_UTF8_ERR10 = C.PCRE2_ERROR_UTF8_ERR10 ERROR_UTF8_ERR11 = C.PCRE2_ERROR_UTF8_ERR11 ERROR_UTF8_ERR12 = C.PCRE2_ERROR_UTF8_ERR12 ERROR_UTF8_ERR13 = C.PCRE2_ERROR_UTF8_ERR13 ERROR_UTF8_ERR14 = C.PCRE2_ERROR_UTF8_ERR14 ERROR_UTF8_ERR15 = C.PCRE2_ERROR_UTF8_ERR15 ERROR_UTF8_ERR16 = C.PCRE2_ERROR_UTF8_ERR16 ERROR_UTF8_ERR17 = C.PCRE2_ERROR_UTF8_ERR17 ERROR_UTF8_ERR18 = C.PCRE2_ERROR_UTF8_ERR18 ERROR_UTF8_ERR19 = C.PCRE2_ERROR_UTF8_ERR19 ERROR_UTF8_ERR20 = C.PCRE2_ERROR_UTF8_ERR20 ERROR_UTF8_ERR21 = C.PCRE2_ERROR_UTF8_ERR21 )
Error codes for UTF-8 validity checks
const ( ERROR_UTF16_ERR1 = C.PCRE2_ERROR_UTF16_ERR1 ERROR_UTF16_ERR2 = C.PCRE2_ERROR_UTF16_ERR2 ERROR_UTF16_ERR3 = C.PCRE2_ERROR_UTF16_ERR3 )
Error codes for UTF-16 validity checks
const ( ERROR_UTF32_ERR1 = C.PCRE2_ERROR_UTF32_ERR1 ERROR_UTF32_ERR2 = C.PCRE2_ERROR_UTF32_ERR2 )
Error codes for UTF-32 validity checks
const ( ERROR_BADDATA = C.PCRE2_ERROR_BADDATA ERROR_MIXEDTABLES = C.PCRE2_ERROR_MIXEDTABLES /* Name was changed */ ERROR_BADMAGIC = C.PCRE2_ERROR_BADMAGIC ERROR_BADMODE = C.PCRE2_ERROR_BADMODE ERROR_BADOFFSET = C.PCRE2_ERROR_BADOFFSET ERROR_BADOPTION = C.PCRE2_ERROR_BADOPTION ERROR_BADREPLACEMENT = C.PCRE2_ERROR_BADREPLACEMENT ERROR_BADUTFOFFSET = C.PCRE2_ERROR_BADUTFOFFSET ERROR_CALLOUT = C.PCRE2_ERROR_CALLOUT /* Never used by PCRE2 itself */ ERROR_DFA_BADRESTART = C.PCRE2_ERROR_DFA_BADRESTART ERROR_DFA_RECURSE = C.PCRE2_ERROR_DFA_RECURSE ERROR_DFA_UCOND = C.PCRE2_ERROR_DFA_UCOND ERROR_DFA_UFUNC = C.PCRE2_ERROR_DFA_UFUNC ERROR_DFA_UITEM = C.PCRE2_ERROR_DFA_UITEM ERROR_DFA_WSSIZE = C.PCRE2_ERROR_DFA_WSSIZE ERROR_INTERNAL = C.PCRE2_ERROR_INTERNAL ERROR_JIT_BADOPTION = C.PCRE2_ERROR_JIT_BADOPTION ERROR_JIT_STACKLIMIT = C.PCRE2_ERROR_JIT_STACKLIMIT ERROR_MATCHLIMIT = C.PCRE2_ERROR_MATCHLIMIT ERROR_NOMEMORY = C.PCRE2_ERROR_NOMEMORY ERROR_NOSUBSTRING = C.PCRE2_ERROR_NOSUBSTRING ERROR_NOUNIQUESUBSTRING = C.PCRE2_ERROR_NOUNIQUESUBSTRING ERROR_NULL = C.PCRE2_ERROR_NULL ERROR_RECURSELOOP = C.PCRE2_ERROR_RECURSELOOP ERROR_RECURSIONLIMIT = C.PCRE2_ERROR_RECURSIONLIMIT /* Obsolete synonym */ ERROR_UNAVAILABLE = C.PCRE2_ERROR_UNAVAILABLE ERROR_UNSET = C.PCRE2_ERROR_UNSET ERROR_BADOFFSETLIMIT = C.PCRE2_ERROR_BADOFFSETLIMIT ERROR_BADREPESCAPE = C.PCRE2_ERROR_BADREPESCAPE ERROR_REPMISSINGBRACE = C.PCRE2_ERROR_REPMISSINGBRACE ERROR_BADSUBSTITUTION = C.PCRE2_ERROR_BADSUBSTITUTION ERROR_BADSUBSPATTERN = C.PCRE2_ERROR_BADSUBSPATTERN ERROR_TOOMANYREPLACE = C.PCRE2_ERROR_TOOMANYREPLACE ERROR_BADSERIALIZEDDATA = C.PCRE2_ERROR_BADSERIALIZEDDATA ERROR_HEAPLIMIT = C.PCRE2_ERROR_HEAPLIMIT ERROR_CONVERT_SYNTAX = C.PCRE2_ERROR_CONVERT_SYNTAX ERROR_INTERNAL_DUPMATCH = C.PCRE2_ERROR_INTERNAL_DUPMATCH )
Error codes for [Dfa]Match(), substring extraction functions, context functions, and serializing functions. They are in numerical order. Originally they were in alphabetical order too, but now that PCRE2 is released, the numbers must not be changed.
const ( INFO_ALLOPTIONS = C.PCRE2_INFO_ALLOPTIONS INFO_ARGOPTIONS = C.PCRE2_INFO_ARGOPTIONS INFO_BACKREFMAX = C.PCRE2_INFO_BACKREFMAX INFO_BSR = C.PCRE2_INFO_BSR INFO_CAPTURECOUNT = C.PCRE2_INFO_CAPTURECOUNT INFO_FIRSTCODEUNIT = C.PCRE2_INFO_FIRSTCODEUNIT INFO_FIRSTCODETYPE = C.PCRE2_INFO_FIRSTCODETYPE INFO_FIRSTBITMAP = C.PCRE2_INFO_FIRSTBITMAP INFO_HASCRORLF = C.PCRE2_INFO_HASCRORLF INFO_JCHANGED = C.PCRE2_INFO_JCHANGED INFO_JITSIZE = C.PCRE2_INFO_JITSIZE INFO_LASTCODEUNIT = C.PCRE2_INFO_LASTCODEUNIT INFO_LASTCODETYPE = C.PCRE2_INFO_LASTCODETYPE INFO_MATCHEMPTY = C.PCRE2_INFO_MATCHEMPTY INFO_MATCHLIMIT = C.PCRE2_INFO_MATCHLIMIT INFO_MAXLOOKBEHIND = C.PCRE2_INFO_MAXLOOKBEHIND INFO_MINLENGTH = C.PCRE2_INFO_MINLENGTH INFO_NAMECOUNT = C.PCRE2_INFO_NAMECOUNT INFO_NAMEENTRYSIZE = C.PCRE2_INFO_NAMEENTRYSIZE INFO_NAMETABLE = C.PCRE2_INFO_NAMETABLE INFO_NEWLINE = C.PCRE2_INFO_NEWLINE INFO_RECURSIONLIMIT = C.PCRE2_INFO_RECURSIONLIMIT /* Obsolete synonym */ INFO_SIZE = C.PCRE2_INFO_SIZE INFO_HASBACKSLASHC = C.PCRE2_INFO_HASBACKSLASHC INFO_FRAMESIZE = C.PCRE2_INFO_FRAMESIZE INFO_HEAPLIMIT = C.PCRE2_INFO_HEAPLIMIT INFO_EXTRAOPTIONS = C.PCRE2_INFO_EXTRAOPTIONS )
Request types for PatternInfo()
const ( CONFIG_BSR = C.PCRE2_CONFIG_BSR CONFIG_JIT = C.PCRE2_CONFIG_JIT CONFIG_JITTARGET = C.PCRE2_CONFIG_JITTARGET CONFIG_LINKSIZE = C.PCRE2_CONFIG_LINKSIZE CONFIG_MATCHLIMIT = C.PCRE2_CONFIG_MATCHLIMIT CONFIG_NEWLINE = C.PCRE2_CONFIG_NEWLINE CONFIG_PARENSLIMIT = C.PCRE2_CONFIG_PARENSLIMIT CONFIG_RECURSIONLIMIT = C.PCRE2_CONFIG_RECURSIONLIMIT /* Obsolete synonym */ CONFIG_STACKRECURSE = C.PCRE2_CONFIG_STACKRECURSE /* Obsolete */ CONFIG_UNICODE = C.PCRE2_CONFIG_UNICODE CONFIG_UNICODE_VERSION = C.PCRE2_CONFIG_UNICODE_VERSION CONFIG_VERSION = C.PCRE2_CONFIG_VERSION CONFIG_HEAPLIMIT = C.PCRE2_CONFIG_HEAPLIMIT CONFIG_NEVER_BACKSLASH_C = C.PCRE2_CONFIG_NEVER_BACKSLASH_C CONFIG_COMPILED_WIDTHS = C.PCRE2_CONFIG_COMPILED_WIDTHS )
Request types for Config().
const ( ZERO_TERMINATED = C.PCRE2_ZERO_TERMINATED UNSET = C.PCRE2_UNSET )
We define special values to indicate zero-terminated strings and unset offsets in the offset vector (ovector).
const (
NO_JIT = C.PCRE2_NO_JIT
)
A further option for Match(), not allowed for DfaMatch(), ignored for JITMatch().
Variables ¶
var ( // ErrInvalidRegexp is returned when the provided Regexp is // not backed by a proper C pointer to pcre2_code ErrInvalidRegexp = errors.New("invalid regexp") )
Functions ¶
func ConfigAll ¶
func ConfigAll() (ret string)
This function returns string, which contains all information you can access by pcre_config() function
func TestCaseless ¶
func TestCaseless()
func TestCompile ¶
func TestCompile()
func TestCompileFail ¶
func TestCompileFail()
func TestExtract ¶
func TestExtract()
func TestExtractString ¶
func TestExtractString()
func TestFindIndex ¶
func TestFindIndex()
func TestMatcher ¶
func TestMatcher()
func TestPartial ¶
func TestPartial()
func TestReplaceAll ¶
func TestReplaceAll()
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 JITError ¶
type JITError struct { ErrorNum int // the error number, one of: ERROR_JIT_BADOPTION, ERROR_NOMEMORY Message string }
JITError holds details about a JIT compilation error, as returned by the CompileJIT function.
type MatchError ¶
MatchError holds details about a matching error.
func (*MatchError) Error ¶
func (e *MatchError) Error() string
Error converts a match error to a string
type Matcher ¶
type Matcher struct { Groups int Matches bool // last match was successful Partial bool // was the last match a partial match? SubjectB []byte // so that Group can return slices SubjectL int // the subject length (bug fix by unixman to avoid PCRE2 overflow as 18446744073709551615) ErrCode int // return code of the match function, useful to know if there was an error // contains filtered or unexported fields }
Matcher objects provide a place for storing match results. They can be created by the Matcher function, or they can be initialized with Reset.
func (*Matcher) Exec ¶
Exec tries to match the specified byte slice to the current pattern. 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 ¶
Same as Extract, but returns []string
func (*Matcher) GetError ¶
GetError returns the error if the matcher encountered an error condition.
func (*Matcher) Group ¶
Group returns the numbered capture group of the last match (performed by Matcher, Reset, Match). 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, Reset, Match). 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) Index ¶
Index returns the start and end of the first match, if a previous call to Matcher, Reset, Match 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) 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 (m *Matcher) NamedPresent(group string) (bool, error) {
type Regexp ¶
type Regexp struct { Pattern string // 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) FindAllIndex ¶
Return the start and end of all matches.
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) JITCompile ¶
JITCompile adds Just-In-Time compilation to a Regexp. This may give a huge speed boost when matching. If an error occurs, return value is non-nil. Flags optionally specifies JIT compilation options for partial matches. The returned value from JITCompile() is nil on success, or an error otherwise. If JIT support is not available, a call to JITCompile() does nothing and returns ERROR_JIT_BADOPTION. If useing this, use also defer re.Free() !
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) NewMatcher ¶
NewMatcher creates a new matcher object for the given Regexp.