beagle

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2019 License: MIT Imports: 2 Imported by: 0

README

Beagle

A super simple regexp wrapper to make things more digestible for the average usecase.

Example Usage

package main

import (
    "fmt"

    "github.com/DaiHasso/beagle"
)

func main() {
    regex := beagle.MustRegex(`(?P<thing>\S+) (are|is) (?P<difficulty>\S+)`)

    result := regex.Match(
        "I heard that go regexps are hard! But maybe it is easy.",
    )

    if result.Matched() {
        fmt.Println("It worked!")
    }

    fmt.Printf(
        "Actually %s %s %s\n",
        result.NamedGroup("thing")[0],
        result.UnamedGroups()[0],
        result.NamedGroup("difficulty")[1],
    )
}

Will result in:

Actually regexps are easy.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Regex

type Regex struct {
	// contains filtered or unexported fields
}

func MakeBetter

func MakeBetter(regex *regexp.Regexp) *Regex

func MakeRegex

func MakeRegex(regex string) (*Regex, error)

func MustRegex

func MustRegex(regex string) *Regex

func (Regex) Match

func (self Regex) Match(target string) *Result

type Result

type Result struct {
	// contains filtered or unexported fields
}

func (Result) Matched added in v0.0.2

func (self Result) Matched() bool

func (Result) MatchedSubstrings

func (self Result) MatchedSubstrings() []string

func (Result) NamedGroup

func (self Result) NamedGroup(key string) []string

func (Result) UnamedGroups

func (self Result) UnamedGroups() []string

Jump to

Keyboard shortcuts

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