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.
const ( None RegexOptions = 0x0 IgnoreCase = 0x0001 // "i" Multiline = 0x0002 // "m" ExplicitCapture = 0x0004 // "n" Compiled = 0x0008 // "c" Singleline = 0x0010 // "s" IgnorePatternWhitespace = 0x0020 // "x" RightToLeft = 0x0040 // "r" Debug = 0x0080 // "d" ECMAScript = 0x0100 // "e" RE2 = 0x0200 // RE2 (regexp package) compatibility mode )
Default timeout used when running regexp matches -- "forever"
Escape adds backslashes to any special characters in the input string
Unescape removes any backslashes from previously-escaped special characters in the input string
Capture is a single capture of text within the larger original string
Runes returns the captured text as a rune slice
String returns the captured text as a String
Group is an explicit or implit (group 0) matched group within the pattern
Match is a single regex result match that contains groups and repeated captures
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)
MatchEvaluator is a function that takes a match and returns a replacement string to be used
RegexOptions impact the runtime and parsing behavior for each specific regex. They are setable in code as well as in the regex pattern itself.
Regexp is the representation of a compiled regular expression. A Regexp is safe for concurrent use by multiple goroutines.
Compile parses a regular expression and returns, if successful, a Regexp object that can be used to match against text.
MustCompile is like Compile but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled regular expressions.
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.
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.
String returns the source text used to compile the regular expression.