regexp

package
v0.12.0 Latest Latest
Warning

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

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

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(re string, lookup interface{}) (*regexp.Regexp, error)

Compile takes a regular expression and a custom lookup struct that should match the named groups in the regexp.

`lookup` should always be a pointer to a struct with only exported `int` properties.

Example
package main

import (
	"fmt"

	"github.com/lunarway/release-manager/internal/regexp"
)

func main() {
	var lookup = struct {
		FirstPart  int
		SecondPart int
	}{}
	re, err := regexp.Compile(`(?P<FirstPart>.+)-(?P<SecondPart>.+)`, &lookup) // Handle err or use MustCompile
	if err != nil {
		panic(err)
	}
	matches := re.FindStringSubmatch("some-message")
	if matches == nil {
		panic("no match")
	}

	fmt.Println(matches[lookup.FirstPart], matches[lookup.SecondPart])
}
Output:

some message

func MustCompile

func MustCompile(re string, lookup interface{}) *regexp.Regexp

Types

This section is empty.

Jump to

Keyboard shortcuts

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