Documentation
¶
Overview ¶
Package regexpand provides a way to expand a regex into a list of strings that it matches.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrorInfinite = errors.New("infinite cardinality")
ErrorInfinite is returned when the regex matches an infinite number of strings.
var ErrorLargeResult = errors.New("large cardinality")
ErrorLargeResult is returned when the regex would result in a large number of strings.
var ErrorUnsupported = errors.New(`regex unsupported`)
ErrorUnsupported is returned when the regex is not supported.
In practice this can happen when:
- a regex contains an alternate with mismatching anchors, such as (a$|b). On the other hand, (a$|b$) and (a|b)$ are supported.
- a regex contains begin of words or end of words anchors such as \b or \B.
Functions ¶
func Expand ¶
Expand takes a regex and returns a list of strings that the regex matches.
Expand operates in O(len(re)*maxLen) time, thus it fails if the regex is too complex and returns ErrorUnsupported. If the number of strings is larger than maxLen, Expand returns ErrorLargeResult. If the regex matches an infinite number of strings, Expand returns ErrorInfinite. If the regex matches an invalid rune, it is substituted with RuneInvalid.
Example ¶
package main import ( "fmt" "github.com/google/regexpand" ) func main() { const maxOutputLen = 100 res, _ := regexpand.Expand(`(?i:p)u[m]p(kin|)s?`, maxOutputLen) fmt.Printf("%+v\n", res) }
Output: [Pump Pumpkin Pumpkins Pumps pump pumpkin pumpkins pumps]
Types ¶
type ASCIISet ¶
type ASCIISet struct {
// contains filtered or unexported fields
}
ASCIISet is a set of ASCII characters.
func ASCIIRange ¶
ASCIIRange returns the set of ASCII characters that are matched by the given regex.
If the regex contains non-ASCII characters, ASCIIRange returns false.
Example ¶
package main import ( "fmt" "github.com/google/regexpand" ) func main() { res, _ := regexpand.ASCIIRange(`\d+`) fmt.Println(res) }
Output: [0-9]