package regexp2

Import Path
	github.com/dlclark/regexp2 (on go.dev)

Dependency Relation
	imports 11 packages, and imported by 3 packages

Involved Source Files fastclock.go match.go Package regexp2 is a regexp package that has an interface similar to Go's framework regexp engine but uses a more feature full regex engine behind the scenes. It doesn't have constant time guarantees, but it allows backtracking and is compatible with Perl5 and .NET. You'll likely be better off with the RE2 engine from the regexp package and should only use this if you need to write very complex patterns or require compatibility with .NET. replace.go runner.go
Package-Level Type Names (total 6)
/* sort by: | */
Capture is a single capture of text within the larger original string Index is the position in the underlying rune slice where the first character of captured substring was found. Even if you pass in a string this will be in Runes. Length is the number of runes in the captured substring. Runes returns the captured text as a rune slice String returns the captured text as a String *Capture : expvar.Var *Capture : fmt.Stringer
Group is an explicit or implit (group 0) matched group within the pattern // the last capture of this group is embeded for ease of use Index is the position in the underlying rune slice where the first character of captured substring was found. Even if you pass in a string this will be in Runes. Length is the number of runes in the captured substring. // captures of this group // group name Runes returns the captured text as a rune slice String returns the captured text as a String *Group : expvar.Var *Group : fmt.Stringer func (*Match).GroupByName(name string) *Group func (*Match).GroupByNumber(num int) *Group func (*Match).Groups() []Group
Match is a single regex result match that contains groups and repeated captures -Groups -Capture // embeded group 0 // the last capture of this group is embeded for ease of use Index is the position in the underlying rune slice where the first character of captured substring was found. Even if you pass in a string this will be in Runes. Length is the number of runes in the captured substring. // captures of this group // group name GroupByName returns a group based on the name of the group, or nil if the group name does not exist GroupByNumber returns a group based on the number of the group, or nil if the group number does not exist GroupCount returns the number of groups this match has matched Groups returns all the capture groups, starting with group 0 (the full match) Runes returns the captured text as a rune slice String returns the captured text as a String *Match : expvar.Var *Match : fmt.Stringer func (*Regexp).FindNextMatch(m *Match) (*Match, error) func (*Regexp).FindRunesMatch(r []rune) (*Match, error) func (*Regexp).FindRunesMatchStartingAt(r []rune, startAt int) (*Match, error) func (*Regexp).FindStringMatch(s string) (*Match, error) func (*Regexp).FindStringMatchStartingAt(s string, startAt int) (*Match, error) func (*Regexp).FindNextMatch(m *Match) (*Match, error)
MatchEvaluator is a function that takes a match and returns a replacement string to be used func (*Regexp).ReplaceFunc(input string, evaluator MatchEvaluator, startAt, count int) (string, error)
RegexOptions impact the runtime and parsing behavior for each specific regex. They are setable in code as well as in the regex pattern itself. func Compile(expr string, opt RegexOptions) (*Regexp, error) func MustCompile(str string, opt RegexOptions) *Regexp var DefaultUnmarshalOptions const None
Regexp is the representation of a compiled regular expression. A Regexp is safe for concurrent use by multiple goroutines. A match will time out if it takes (approximately) more than MatchTimeout. This is a safety check in case the match encounters catastrophic backtracking. The default value (DefaultMatchTimeout) causes all time out checking to be suppressed. (*Regexp) Debug() bool FindNextMatch returns the next match in the same input string as the match parameter. Will return nil if there is no next match or if given a nil match. FindRunesMatch searches the input rune slice for a Regexp match FindRunesMatchStartingAt searches the input rune slice for a Regexp match starting at the startAt index FindStringMatch searches the input string for a Regexp match FindStringMatchStartingAt searches the input string for a Regexp match starting at the startAt index GetGroupNames Returns the set of strings used to name capturing groups in the expression. GetGroupNumbers returns the integer group numbers corresponding to a group name. GroupNameFromNumber retrieves a group name that corresponds to a group number. It will return "" for and unknown group number. Unnamed groups automatically receive a name that is the decimal string equivalent of its number. GroupNumberFromName returns a group number that corresponds to a group name. Returns -1 if the name is not a recognized group name. Numbered groups automatically get a group name that is the decimal string equivalent of its number. MarshalText implements [encoding.TextMarshaler]. The output matches that of calling the [Regexp.String] method. MatchRunes return true if the runes matches the regex error will be set if a timeout occurs MatchString return true if the string matches the regex error will be set if a timeout occurs Replace searches the input string and replaces each match found with the replacement text. Count will limit the number of matches attempted and startAt will allow us to skip past possible matches at the start of the input (left or right depending on RightToLeft option). Set startAt and count to -1 to go through the whole string ReplaceFunc searches the input string and replaces each match found using the string from the evaluator Count will limit the number of matches attempted and startAt will allow us to skip past possible matches at the start of the input (left or right depending on RightToLeft option). Set startAt and count to -1 to go through the whole string. (*Regexp) RightToLeft() bool String returns the source text used to compile the regular expression. UnmarshalText implements [encoding.TextUnmarshaler] by calling [Compile] on the encoded value. *Regexp : encoding.TextMarshaler *Regexp : encoding.TextUnmarshaler *Regexp : expvar.Var *Regexp : fmt.Stringer func Compile(expr string, opt RegexOptions) (*Regexp, error) func MustCompile(str string, opt RegexOptions) *Regexp
Package-Level Functions (total 6)
Compile parses a regular expression and returns, if successful, a Regexp object that can be used to match against text.
Escape adds backslashes to any special characters in the input string
MustCompile is like Compile but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled regular expressions.
SetTimeoutPeriod is a debug function that sets the frequency of the timeout goroutine's sleep cycle. Defaults to 100ms. The only benefit of setting this lower is that the 1 background goroutine that manages timeouts may exit slightly sooner after all the timeouts have expired. See Github issue #63
StopTimeoutClock should only be used in unit tests to prevent the timeout clock goroutine from appearing like a leaking goroutine
Unescape removes any backslashes from previously-escaped special characters in the input string
Package-Level Variables (total 2)
DefaultMatchTimeout used when running regexp matches -- "forever"
DefaultUnmarshalOptions used when unmarshaling a regex from text
Package-Level Constants (total 13)
const Compiled = 8 // "c"
const Debug = 128 // "d"
const DefaultClockPeriod time.Duration = 100000000
const ECMAScript = 256 // "e"
const ExplicitCapture = 4 // "n"
const IgnoreCase = 1 // "i"
const IgnorePatternWhitespace = 32 // "x"
const Multiline = 2 // "m"
const None RegexOptions = 0
const RE2 = 512 // RE2 (regexp package) compatibility mode
const RightToLeft = 64 // "r"
const Singleline = 16 // "s"
const Unicode = 1024 // "u"