regexp

package
v0.3.0-alpha6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

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 added in v0.1.0

func Valid(pattern string) (bool, error)

Valid reports whether the given regular expression is valid.

Types

This section is empty.

Jump to

Keyboard shortcuts

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