Documentation
¶
Overview ¶
Package regexutil provides utilities for safe regex handling.
Index ¶
Constants ¶
const ( // MaxPatternLength is the maximum allowed regex pattern length. MaxPatternLength = 1000 // MaxRepetitionCount is the maximum allowed repetition count (e.g., a{1000}). MaxRepetitionCount = 100 // MaxNestedQuantifiers is the maximum depth of nested quantifiers. MaxNestedQuantifiers = 3 // CompileTimeout is the maximum time to spend compiling a regex. CompileTimeout = 100 * time.Millisecond )
Limits for regex patterns to prevent ReDoS attacks.
Variables ¶
This section is empty.
Functions ¶
func MustSafeCompile ¶
MustSafeCompile is like SafeCompile but panics on error. Only use for patterns known at compile time.
func SafeCompile ¶
SafeCompile validates and compiles a regex pattern with safety checks. Returns the compiled regex or an error if the pattern is unsafe or invalid.
func SafeCompileWithFlags ¶
SafeCompileWithFlags validates and compiles a regex with the given flags prefix. Common flags: "(?i)" for case-insensitive, "(?m)" for multiline.
func ValidatePattern ¶
ValidatePattern checks if a regex pattern is safe to compile and execute. Returns nil if the pattern is safe, or a ValidationError explaining the issue.
Types ¶
type ValidationError ¶
ValidationError represents a regex validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string