reutils

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteRegexGroup

func DeleteRegexGroup(key string) (result []*regexp.Regexp)

DeleteRegexGroup tries to retreive a regular expression group previously created by NewRegexGroup.

Example
NewRegexGroup("test", `^\w+$`, `^Hello (?P<who>\w+).*$`)
result := DeleteRegexGroup("test")
fmt.Println(result)
Output:
[^\w+$ ^Hello (?P<who>\w+).*$]
Example (Not_existing)
result := DeleteRegexGroup("not existing")
fmt.Println(result)
Output:
[]

func GetRegexGroup

func GetRegexGroup(key string) (result []*regexp.Regexp)

GetRegexGroup tries to retreive a regular expression group previously created by NewRegexGroup.

Example
// Create a group.
if _, err := NewRegexGroup("test", `^\w+$`, `^Hello (?P<who>\w+).*$`); err != nil {
	fmt.Println("Invalid group definition", err)
}

result, match := MultiMatch("Hello world!", GetRegexGroup("test")...)
fmt.Printf("Matched group %d\n", match)
fmt.Println(result)
Output:
Matched group 1
map[:Hello world! who:world]

func MultiMatch

func MultiMatch(s string, expressions ...*regexp.Regexp) (map[string]string, int)

MultiMatch returns a map of matching elements from a list of regular expressions (returning the first matching element).

func NewRegexGroup

func NewRegexGroup(key string, definitions ...string) (result []*regexp.Regexp, err error)

NewRegexGroup cache compiled regex to avoid multiple interpretation of the same regex.

Example (With_error)
// All supplied regular expressions must be valid.
if _, err := NewRegexGroup("test", `^\w+$`, `^Hello (?P(who)\w+).*$`); err != nil {
	fmt.Println("Invalid group definition", err)
}
Output:
Invalid group definition error parsing regexp: invalid or unsupported Perl syntax: `(?P`

Types

This section is empty.

Jump to

Keyboard shortcuts

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