regex

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(d, template []byte, r *regexp.Regexp, n int) []byte

Expand appends template to the result and during append it replaces variables in the template with n number of matches drawn from the source data d.

In the template, a variable is denoted by a substring of the form $name or ${name}, where name is a non-empty sequence of letters, digits, and underscores. A purely numeric name like $1 refers to the sub-match with the corresponding index; other names refer to capturing parentheses named with the (?P<name>...) syntax. A reference to an out of range or unmatched index or a name that is not present in the regular expression is replaced with an empty slice.

In the $name form, name is taken to be as long as possible: $1x is equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0.

To insert a literal $ in the output, use $$ in the template.

func ExpandAll

func ExpandAll(d, template []byte, r *regexp.Regexp) []byte

ExpandAll appends template to the result and during append it replaces variables in the template with all the matches drawn from the source data d.

In the template, a variable is denoted by a substring of the form $name or ${name}, where name is a non-empty sequence of letters, digits, and underscores. A purely numeric name like $1 refers to the sub-match with the corresponding index; other names refer to capturing parentheses named with the (?P<name>...) syntax. A reference to an out of range or unmatched index or a name that is not present in the regular expression is replaced with an empty slice.

In the $name form, name is taken to be as long as possible: $1x is equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0.

To insert a literal $ in the output, use $$ in the template.

func ExpandAllString

func ExpandAllString(d, template string, r *regexp.Regexp) string

ExpandAllString is like ExpandAll but the template and source are strings.

func ExpandAllStringWithPattern

func ExpandAllStringWithPattern(d, template string, pattern string) string

ExpandAllStringWithPattern is like ExpandAllString but instead of a regex, it takes a pattern to match the content.

func ExpandAllWithPattern

func ExpandAllWithPattern(d, template []byte, pattern string) []byte

ExpandAllWithPattern is like ExpandAll but instead of a regex, it takes a pattern to match the content.

func ExpandString

func ExpandString(d, template string, r *regexp.Regexp, n int) string

ExpandString is like Expand but the template and source are strings.

func ExpandStringWithPattern

func ExpandStringWithPattern(d, template string, pattern string, n int) string

ExpandStringWithPattern is like ExpandString but instead of a regex, it takes a pattern to match the content.

func ExpandWithPattern

func ExpandWithPattern(d, template []byte, pattern string, n int) []byte

ExpandWithPattern is like Expand but instead of a regex, it takes a pattern to match the content.

func Find

func Find(d []byte, r *regexp.Regexp, n int) [][]byte

Find returns a slice of max n successive matches in d of the regular expression. A return value of nil indicates no match.

func FindAll

func FindAll(d []byte, r *regexp.Regexp) [][]byte

FindAll returns a slice of all successive matches in d of the regular expression.

func FindAllIndex

func FindAllIndex(d []byte, r *regexp.Regexp) []*pair.Pair[int, int]

FindAllIndex returns a slice of all successive matching indices in d of the regular expression.

func FindAllIndexForString

func FindAllIndexForString(d string, r *regexp.Regexp) []*pair.Pair[int, int]

FindAllIndexForString is like FindAllIndex but the source d is a string.

func FindAllIndexForStringWithPattern

func FindAllIndexForStringWithPattern(d string, pattern string) []*pair.Pair[int, int]

FindAllIndexForStringWithPattern is like FindAllIndexForString but instead of a regex, it takes a pattern to match the content.

func FindAllIndexWithPattern

func FindAllIndexWithPattern(d []byte, pattern string) []*pair.Pair[int, int]

FindAllIndexWithPattern is like FindAllIndex but instead of a regex, it takes a pattern to match the content.

func FindAllString

func FindAllString(d string, r *regexp.Regexp) []string

FindAllString is like FindAll but the source d is a string.

func FindAllStringWithPattern

func FindAllStringWithPattern(d string, pattern string) []string

FindAllStringWithPattern is like FindAllString but instead of a regex, it takes a pattern to match the content.

func FindAllSubMatches

func FindAllSubMatches(d []byte, r *regexp.Regexp) [][][]byte

FindAllSubMatches returns a slice of slices holding the text of all sub-matches of the regular expression in d and the matches, if any, of its subexpressions, as defined by the 'SubMatch' descriptions in the package comment. A return value of nil indicates no match.

func FindAllSubMatchesForString

func FindAllSubMatchesForString(d string, r *regexp.Regexp) [][]string

FindAllSubMatchesForString is like FindAllSubMatches but the source d is a string.

func FindAllSubMatchesForStringWithPattern

func FindAllSubMatchesForStringWithPattern(d string, pattern string) [][]string

FindAllSubMatchesForStringWithPattern is like FindAllSubMatchesForString but instead of a regex, it takes a pattern to match the content.

func FindAllSubMatchesWithPattern

func FindAllSubMatchesWithPattern(d []byte, pattern string) [][][]byte

FindAllSubMatchesWithPattern is like FindAllSubMatches but instead of a regex, it takes a pattern to match the content.

func FindAllSubMatchingIndices

func FindAllSubMatchingIndices(d []byte, r *regexp.Regexp) [][]*pair.Pair[int, int]

FindAllSubMatchingIndices returns a slice of slices holding the index pairs identifying the all the sub-matches of the regular expression in d and the matches, if any, of its subexpressions, as defined by the 'SubMatch' descriptions in the package comment. A return value of nil indicates no match.

func FindAllSubMatchingIndicesForString

func FindAllSubMatchingIndicesForString(d string, r *regexp.Regexp) [][]*pair.Pair[int, int]

FindAllSubMatchingIndicesForString is like FindAllSubMatchingIndices but the source d is a string.

func FindAllSubMatchingIndicesForStringWithPattern

func FindAllSubMatchingIndicesForStringWithPattern(d string, pattern string) [][]*pair.Pair[int, int]

FindAllSubMatchingIndicesForStringWithPattern is like FindAllSubMatchingIndicesForString but instead of a regex, it takes a pattern to match the content.

func FindAllSubMatchingIndicesWithPattern

func FindAllSubMatchingIndicesWithPattern(d []byte, pattern string) [][]*pair.Pair[int, int]

FindAllSubMatchingIndicesWithPattern is like FindAllSubMatchingIndices but instead of a regex, it takes a pattern to match the content.

func FindAllWithPattern

func FindAllWithPattern(d []byte, pattern string) [][]byte

FindAllWithPattern is like FindAll but instead of a regex, it takes a pattern to match the content.

func FindFirst

func FindFirst(d []byte, r *regexp.Regexp) []byte

FindFirst returns the leftmost match in d of the regular expression. A return value of nil indicates no match.

func FindFirstIndex

func FindFirstIndex(d []byte, r *regexp.Regexp) *pair.Pair[int, int]

FindFirstIndex returns the leftmost matching index in d of the regular expression. A return value of nil indicates no match.

func FindFirstIndexForString

func FindFirstIndexForString(d string, r *regexp.Regexp) *pair.Pair[int, int]

FindFirstIndexForString is like FindFirstIndex but the source d is a string.

func FindFirstIndexForStringWithPattern

func FindFirstIndexForStringWithPattern(d string, pattern string) *pair.Pair[int, int]

FindFirstIndexForStringWithPattern is like FindFirstIndexForString but instead of a regex, it takes a pattern to match the content.

func FindFirstIndexWithPattern

func FindFirstIndexWithPattern(d []byte, pattern string) *pair.Pair[int, int]

FindFirstIndexWithPattern is like FindFirstIndex but instead of a regex, it takes a pattern to match the content.

func FindFirstString

func FindFirstString(d string, r *regexp.Regexp) string

FindFirstString is like FindFirst but the source d is a string.

func FindFirstStringWithPattern

func FindFirstStringWithPattern(d string, pattern string) string

FindFirstStringWithPattern is like FindFirstString but instead of a regex, it takes a pattern to match the content.

func FindFirstSubMatch

func FindFirstSubMatch(d []byte, r *regexp.Regexp) [][]byte

FindFirstSubMatch returns a slice of slices holding the text of the leftmost sub-match of the regular expression in b and the matches, if any, of its subexpressions, as defined by the 'SubMatch' descriptions in the package comment. A return value of nil indicates no match.

func FindFirstSubMatchForString

func FindFirstSubMatchForString(d string, r *regexp.Regexp) []string

FindFirstSubMatchForString is like FindFirstSubMatch but the source d is a string.

func FindFirstSubMatchForStringWithPattern

func FindFirstSubMatchForStringWithPattern(d string, pattern string) []string

FindFirstSubMatchForStringWithPattern is like FindFirstSubMatchForString but instead of a regex, it takes a pattern to match the content.

func FindFirstSubMatchWithPattern

func FindFirstSubMatchWithPattern(d []byte, pattern string) [][]byte

FindFirstSubMatchWithPattern is like FindFirstSubMatch but instead of a regex, it takes a pattern to match the content.

func FindFirstSubMatchingIndex

func FindFirstSubMatchingIndex(d []byte, r *regexp.Regexp) []*pair.Pair[int, int]

FindFirstSubMatchingIndex returns a slice holding the index pairs identifying the leftmost sub-match of the regular expression in b and the matches, if any, of its subexpressions, as defined by the 'SubMatch'. A return value of nil indicates no match.

func FindFirstSubMatchingIndexForString

func FindFirstSubMatchingIndexForString(d string, r *regexp.Regexp) []*pair.Pair[int, int]

FindFirstSubMatchingIndexForString is like FindFirstSubMatchingIndex but the source d is a string.

func FindFirstSubMatchingIndexForStringWithPattern

func FindFirstSubMatchingIndexForStringWithPattern(d string, pattern string) []*pair.Pair[int, int]

FindFirstSubMatchingIndexForStringWithPattern is like FindFirstSubMatchingIndexForString but instead of a regex, it takes a pattern to match the content.

func FindFirstSubMatchingIndexWithPattern

func FindFirstSubMatchingIndexWithPattern(d []byte, pattern string) []*pair.Pair[int, int]

FindFirstSubMatchingIndexWithPattern is like FindFirstSubMatchingIndex but instead of a regex, it takes a pattern to match the content.

func FindFirstWithPattern

func FindFirstWithPattern(d []byte, pattern string) []byte

FindFirstWithPattern is like FindFirst but instead of a regex, it takes a pattern to match the content.

func FindIndex

func FindIndex(d []byte, r *regexp.Regexp, n int) []*pair.Pair[int, int]

FindIndex returns a slice of max n successive matching indices in d of the regular expression. A return value of nil indicates no match.

func FindIndexForString

func FindIndexForString(d string, r *regexp.Regexp, n int) []*pair.Pair[int, int]

FindIndexForString is like FindIndex but the source d is a string.

func FindIndexForStringWithPattern

func FindIndexForStringWithPattern(d string, pattern string, n int) []*pair.Pair[int, int]

FindIndexForStringWithPattern is like FindIndexForString but instead of a regex, it takes a pattern to match the content.

func FindIndexWithPattern

func FindIndexWithPattern(d []byte, pattern string, n int) []*pair.Pair[int, int]

FindIndexWithPattern is like FindIndex but instead of a regex, it takes a pattern to match the content.

func FindLast

func FindLast(d []byte, r *regexp.Regexp) []byte

FindLast returns the rightmost match in d of the regular expression. A return value of nil indicates no match.

func FindLastIndex

func FindLastIndex(d []byte, r *regexp.Regexp) *pair.Pair[int, int]

FindLastIndex returns the rightmost matching index in d of the regular expression. A return value of nil indicates no match.

func FindLastIndexForString

func FindLastIndexForString(d string, r *regexp.Regexp) *pair.Pair[int, int]

FindLastIndexForString is like FindLastIndex but the source d is a string.

func FindLastIndexForStringWithPattern

func FindLastIndexForStringWithPattern(d string, pattern string) *pair.Pair[int, int]

FindLastIndexForStringWithPattern is like FindLastIndexForString but instead of a regex, it takes a pattern to match the content.

func FindLastIndexWithPattern

func FindLastIndexWithPattern(d []byte, pattern string) *pair.Pair[int, int]

FindLastIndexWithPattern is like FindLastIndex but instead of a regex, it takes a pattern to match the content.

func FindLastString

func FindLastString(d string, r *regexp.Regexp) string

FindLastString is like FindLast but the source d is a string.

func FindLastStringWithPattern

func FindLastStringWithPattern(d string, pattern string) string

FindLastStringWithPattern is like FindLastString but instead of a regex, it takes a pattern to match the content.

func FindLastSubMatch

func FindLastSubMatch(d []byte, r *regexp.Regexp) [][]byte

FindLastSubMatch returns a slice of slices holding the text of the rightmost sub-match of the regular expression in b and the matches, if any, of its subexpressions, as defined by the 'SubMatch' descriptions in the package comment. A return value of nil indicates no match.

func FindLastSubMatchForString

func FindLastSubMatchForString(d string, r *regexp.Regexp) []string

FindLastSubMatchForString is like FindLastSubMatch but the source d is a string.

func FindLastSubMatchForStringWithPattern

func FindLastSubMatchForStringWithPattern(d string, pattern string) []string

FindLastSubMatchForStringWithPattern is like FindLastSubMatchForString but instead of a regex, it takes a pattern to match the content.

func FindLastSubMatchWithPattern

func FindLastSubMatchWithPattern(d []byte, pattern string) [][]byte

FindLastSubMatchWithPattern is like FindLastSubMatch but instead of a regex, it takes a pattern to match the content.

func FindLastSubMatchingIndex

func FindLastSubMatchingIndex(d []byte, r *regexp.Regexp) []*pair.Pair[int, int]

FindLastSubMatchingIndex returns a slice holding the index pairs identifying the rightmost sub-match of the regular expression in b and the matches, if any, of its subexpressions, as defined by the 'SubMatch'. A return value of nil indicates no match.

func FindLastSubMatchingIndexForString

func FindLastSubMatchingIndexForString(d string, r *regexp.Regexp) []*pair.Pair[int, int]

FindLastSubMatchingIndexForString is like FindLastSubMatchingIndex but the source d is a string.

func FindLastSubMatchingIndexForStringWithPattern

func FindLastSubMatchingIndexForStringWithPattern(d string, pattern string) []*pair.Pair[int, int]

FindLastSubMatchingIndexForStringWithPattern is like FindLastSubMatchingIndexForString but instead of a regex, it takes a pattern to match the content.

func FindLastSubMatchingIndexWithPattern

func FindLastSubMatchingIndexWithPattern(d []byte, pattern string) []*pair.Pair[int, int]

FindLastSubMatchingIndexWithPattern is like FindLastSubMatchingIndex but instead of a regex, it takes a pattern to match the content.

func FindLastWithPattern

func FindLastWithPattern(d []byte, pattern string) []byte

FindLastWithPattern is like FindLast but instead of a regex, it takes a pattern to match the content.

func FindString

func FindString(d string, r *regexp.Regexp, n int) []string

FindString is like Find but the source d is a string.

func FindStringWithPattern

func FindStringWithPattern(d string, pattern string, n int) []string

FindStringWithPattern is like FindString but instead of a regex, it takes a pattern to match the content.

func FindSubMatches

func FindSubMatches(d []byte, r *regexp.Regexp, n int) [][][]byte

FindSubMatches returns a slice of slices holding the text of the n number of sub-matches of the regular expression in d and the matches, if any, of its subexpressions, as defined by the 'SubMatch' descriptions in the package comment. A return value of nil indicates no match.

func FindSubMatchesForString

func FindSubMatchesForString(d string, r *regexp.Regexp, n int) [][]string

FindSubMatchesForString is like FindSubMatches but the source d is a string.

func FindSubMatchesForStringWithPattern

func FindSubMatchesForStringWithPattern(d string, pattern string, n int) [][]string

FindSubMatchesForStringWithPattern is like FindSubMatchesForString but instead of a regex, it takes a pattern to match the content.

func FindSubMatchesWithPattern

func FindSubMatchesWithPattern(d []byte, pattern string, n int) [][][]byte

FindSubMatchesWithPattern is like FindSubMatches but instead of a regex, it takes a pattern to match the content.

func FindSubMatchingIndices

func FindSubMatchingIndices(d []byte, r *regexp.Regexp, n int) [][]*pair.Pair[int, int]

FindSubMatchingIndices returns a slice of slices holding the index pairs identifying the n number of sub-matches of the regular expression in d and the matches, if any, of its subexpressions, as defined by the 'SubMatch' descriptions in the package comment. A return value of nil indicates no match.

func FindSubMatchingIndicesForString

func FindSubMatchingIndicesForString(d string, r *regexp.Regexp, n int) [][]*pair.Pair[int, int]

FindSubMatchingIndicesForString is like FindSubMatchingIndices but the source d is a string.

func FindSubMatchingIndicesForStringWithPattern

func FindSubMatchingIndicesForStringWithPattern(d string, pattern string, n int) [][]*pair.Pair[int, int]

FindSubMatchingIndicesForStringWithPattern is like FindSubMatchingIndicesForString but instead of a regex, it takes a pattern to match the content.

func FindSubMatchingIndicesWithPattern

func FindSubMatchingIndicesWithPattern(d []byte, pattern string, n int) [][]*pair.Pair[int, int]

FindSubMatchingIndicesWithPattern is like FindSubMatchingIndices but instead of a regex, it takes a pattern to match the content.

func FindWithPattern

func FindWithPattern(d []byte, pattern string, n int) [][]byte

FindWithPattern is like Find but instead of a regex, it takes a pattern to match the content.

func Match

func Match(d []byte, r *regexp.Regexp) bool

Match reports whether the byte slice d contains any match of the regular expression r.

func MatchString

func MatchString(d string, r *regexp.Regexp) bool

MatchString is like Match but the source d is a string.

func MatchStringWithPattern

func MatchStringWithPattern(d string, pattern string) bool

MatchStringWithPattern is like MatchString but instead of a regex, it takes a pattern to match the content.

func MatchWithPattern

func MatchWithPattern(d []byte, pattern string) bool

MatchWithPattern is like Match but instead of a regex, it takes a pattern to match the content.

func RemoveAll

func RemoveAll(d []byte, r *regexp.Regexp) []byte

RemoveAll is used to remove all the matches of the regex in the given data.

func RemoveAllString

func RemoveAllString(s string, r *regexp.Regexp) string

RemoveAllString is used to remove all the matches of the regex in the given string.

func RemoveAllStringWithPattern

func RemoveAllStringWithPattern(s, pattern string) string

RemoveAllStringWithPattern is used to remove all the matches of the pattern in the given string.

func RemoveAllWithPattern

func RemoveAllWithPattern(d []byte, pattern string) []byte

RemoveAllWithPattern is used to remove all the matches of the pattern in the given data.

func ReplaceAll

func ReplaceAll(d []byte, r *regexp.Regexp, replacement []byte) []byte

ReplaceAll is used to replace all the matches of the regex in the given data with the replacement. Inside replacement, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first sub-match.

func ReplaceAllString

func ReplaceAllString(s string, r *regexp.Regexp, replacement string) string

ReplaceAllString is used to replace all the matches of the regex in the given string with the replacement. Inside replacement, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first sub-match.

func ReplaceAllStringWithPattern

func ReplaceAllStringWithPattern(s, pattern, replacement string) string

ReplaceAllStringWithPattern is used to replace all the matches of the pattern in the given string with the replacement. Inside replacement, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first sub-match.

func ReplaceAllWithPattern

func ReplaceAllWithPattern(d []byte, pattern string, replacement []byte) []byte

ReplaceAllWithPattern is used to replace all the matches of the pattern in the given data with the replacement. Inside replacement, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first sub-match.

Types

This section is empty.

Jump to

Keyboard shortcuts

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