Back to godoc.org
cuelang.org/go / pkg / regexp

Package regexp

v0.2.2
Latest Go to latest
Published: Jul 18, 2020 | License: Apache-2.0 | Module: cuelang.org/go

Index

Package Files

func Find

func Find(pattern, s string) (string, error)

Find returns a string holding the text of the leftmost match in s of the regular expression. It returns bottom if there was no match.

func FindAll

func FindAll(pattern, s string, n int) ([]string, error)

FindAll returns a list of all successive matches of the expression. It matches successive non-overlapping matches of the entire expression. Empty matches abutting a preceding match are ignored. The return value is a list containing the successive matches. The integer argument n indicates the maximum number of matches to return for n >= 0, or all matches otherwise. It returns bottom for no match.

func FindAllNamedSubmatch

func FindAllNamedSubmatch(pattern, s string, n int) ([]map[string]string, error)

FindAllNamedSubmatch is like FindAllSubmatch, but returns a map with the named used in capturing groups. See FindNamedSubmatch for an example on how to use named groups.

func FindAllSubmatch

func FindAllSubmatch(pattern, s string, n int) ([][]string, error)

FindAllSubmatch finds successive matches as returned by FindSubmatch, observing the rules of FindAll. It returns bottom for no match.

func FindNamedSubmatch

func FindNamedSubmatch(pattern, s string) (map[string]string, error)

FindNamedSubmatch is like FindSubmatch, but returns a map with the names used in capturing groups.

Example:

   regexp.MapSubmatch(#"Hello (?P<person>\w*)!"#, "Hello World!")
Output:
   [{person: "World"}]

func FindSubmatch

func FindSubmatch(pattern, s string) ([]string, error)

FindSubmatch returns a list of strings holding the text of the leftmost match of the regular expression in s and the matches, if any, of its subexpressions. Submatches are matches of parenthesized subexpressions (also known as capturing groups) within the regular expression, numbered from left to right in order of opening parenthesis. Submatch 0 is the match of the entire expression, submatch 1 the match of the first parenthesized subexpression, and so on. It returns bottom for no match.

func Match

func Match(pattern string, s string) (matched bool, err error)

Match reports whether the string s contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

func QuoteMeta

func QuoteMeta(s string) string

QuoteMeta returns a string that escapes all regular expression metacharacters inside the argument text; the returned string is a regular expression matching the literal text.

func Valid

func Valid(pattern string) (bool, error)

Valid reports whether the given regular expression is valid.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier