pcre2

package module
v0.0.0-...-bd52ad5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2019 License: BSD-3-Clause Imports: 7 Imported by: 1

README

go-pcre2

GoDoc

This is a Go language package providing support for version 2 of Perl Compatible Regular Expressions (PCRE).

Installation

Install the package for Debian as follows:

sudo apt-get install libpcre2-dev
go get github.com/Jemmic/go-pcre2

Usage

Go programs that depend on this package should import this package as follows to allow automatic downloading:

import "github.com/Jemmic/go-pcre2"

History

This is based on go-pcre by gijsbers and go-pcre2 by lestrrat.

Documentation

Overview

Package pcre2 provides access to version 2 of the Perl Compatible Regular Expresion library, PCRE.

It implements two main types, Regexp and Matcher. Regexp objects store a compiled regular expression. They consist of two immutable parts: pcre and pcre_extra. Compile()/MustCompile() initialize pcre. Calling Study() on a compiled Regexp initializes pcre_extra. 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. CompileJIT and MustCompileJIT are way more expensive, because they run Study() after compiling a Regexp, but they tend to give much better performance: http://sljit.sourceforge.net/regex_perf.html

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. http://www.pcre.org/pcre2.txt

Index

Constants

View Source
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.

View Source
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

View Source
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.

View Source
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()

View Source
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.

View Source
const (
	DFA_RESTART  = C.PCRE2_DFA_RESTART
	DFA_SHORTEST = C.PCRE2_DFA_SHORTEST
)

These are additional options for DfaMatch().

View Source
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().

View Source
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().

View Source
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.

View Source
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().

View Source
const (
	ERROR_NOMATCH = C.PCRE2_ERROR_NOMATCH
	ERROR_PARTIAL = C.PCRE2_ERROR_PARTIAL
)

"Expected" matching error codes: no match and partial match.

View Source
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

View Source
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

View Source
const (
	ERROR_UTF32_ERR1 = C.PCRE2_ERROR_UTF32_ERR1
	ERROR_UTF32_ERR2 = C.PCRE2_ERROR_UTF32_ERR2
)

Error codes for UTF-32 validity checks

View Source
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.

View Source
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()

View Source
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().

View Source
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).

View Source
const (
	NO_JIT = C.PCRE2_NO_JIT
)

A further option for Match(), not allowed for DfaMatch(), ignored for JITMatch().

Variables

View Source
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

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 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.

func (*JITError) Error

func (e *JITError) Error() string

Error converts a compile error to a string

type MatchError

type MatchError struct {
	ErrorNum int // the error number
	Message  string
}

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 {
	// 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

func (m *Matcher) Exec(subject []byte, flags uint32) int

Exec tries to match the specified byte slice to the current pattern. Returns the raw pcre_exec error code.

func (*Matcher) ExecString

func (m *Matcher) ExecString(subject string, flags uint32) int

ExecString tries to match the specified subject string to the current pattern. It returns the raw pcre_exec error code.

func (*Matcher) Extract

func (m *Matcher) Extract() [][]byte

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

func (m *Matcher) ExtractString() []string

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) Free

func (m *Matcher) Free()

Free releases the underlying C resources

func (*Matcher) GetError

func (m *Matcher) GetError() error

GetError returns the error if the matcher encountered an error condition.

func (*Matcher) Group

func (m *Matcher) Group(group int) []byte

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

func (m *Matcher) GroupIndices(group int) []int

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

func (m *Matcher) GroupString(group int) string

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) Groups

func (m *Matcher) Groups() int

Groups returns the number of groups in the current pattern.

func (*Matcher) HasError

func (m *Matcher) HasError() bool

HasError returns whether the matcher encountered an error condition.

func (*Matcher) Index

func (m *Matcher) Index() (loc []int)

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) Init

func (m *Matcher) Init(re *Regexp)

Init binds an existing Matcher object to the given Regexp.

func (*Matcher) Match

func (m *Matcher) Match(subject []byte, flags uint32) bool

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

func (m *Matcher) MatchString(subject string, flags uint32) bool

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

func (m *Matcher) Matches() bool

Matches returns true if a previous call to Matcher, MatcherString, Reset, ResetString, Match or MatchString succeeded.

func (*Matcher) Named

func (m *Matcher) Named(group string) ([]byte, error)

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

func (m *Matcher) NamedPresent(group string) (bool, error)

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

func (m *Matcher) NamedString(group string) (string, error)

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

func (m *Matcher) Partial() bool

Partial returns true if a previous call to Matcher, MatcherString, Reset, ResetString, Match or MatchString found a partial match.

func (*Matcher) Present

func (m *Matcher) Present(group int) bool

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.

func (*Matcher) Reset

func (m *Matcher) Reset(re *Regexp, subject []byte, flags uint32) bool

Reset switches the matcher object to the specified regexp and subject. It also starts a first match on subject.

func (*Matcher) ResetString

func (m *Matcher) ResetString(re *Regexp, subject string, flags uint32) bool

ResetString switches the matcher object to the given regexp and subject. It also starts a first match on subject.

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

func Compile(pattern string, flags uint32) (*Regexp, error)

Compile the pattern and return a compiled regexp. If compilation fails, the second return value holds a *CompileError.

func CompileJIT

func CompileJIT(pattern string, comFlags, jitFlags uint32) (*Regexp, error)

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

func MustCompile(pattern string, flags uint32) (re *Regexp)

MustCompile compiles the pattern. If compilation fails, panic.

func MustCompileJIT

func MustCompileJIT(pattern string, comFlags, jitFlags uint32) (re *Regexp)

MustCompileJIT compiles and studies the pattern. On failure it panics.

func (*Regexp) FindIndex

func (re *Regexp) FindIndex(bytes []byte, flags uint32) (loc []int)

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) Free

func (re *Regexp) Free() error

Free releases the underlying C resources

func (*Regexp) Groups

func (re *Regexp) Groups() int

Groups returns the number of capture groups in the compiled pattern.

func (*Regexp) JITCompile

func (re *Regexp) JITCompile(flags uint32) error

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.

func (*Regexp) Matcher

func (re *Regexp) Matcher(subject []byte, flags uint32) (m *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

func (re *Regexp) MatcherString(subject string, flags uint32) (m *Matcher)

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

func (re *Regexp) NewMatcher() (m *Matcher)

NewMatcher creates a new matcher object for the given Regexp.

func (*Regexp) ReplaceAll

func (re *Regexp) ReplaceAll(bytes, repl []byte, flags uint32) []byte

ReplaceAll returns a copy of a byte slice where all pattern matches are replaced by repl.

func (*Regexp) ReplaceAllString

func (re *Regexp) ReplaceAllString(in, repl string, flags uint32) string

ReplaceAllString is equivalent to ReplaceAll with string return type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL