Skip to content

Multiregexp makes a set of regular expression. And applies some functions for match.

License

Notifications You must be signed in to change notification settings

rueyaa332266/multiregexp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multiregexp

Go Report Card GoDoc Software License

Package multiregexp helps to make a set of regular expression. And it applies functions to logical join the match result in the set.

Installation

Get the package.

go get github.com/rueyaa332266/multiregexp

Import in the code.

import (
  "github.com/rueyaa332266/multiregexp"
)

Usage

Make a set of regexp and match the string

package main

import (
	"fmt"
	"regexp"

  "github.com/rueyaa332266/multiregexp"
)

func main() {
	// Make an empty Regexps
	var regs multiregexp.Regexps

	re1 := regexp.MustCompile(`\d`)
	re2 := regexp.MustCompile(`[a-z]`)
	re3 := regexp.MustCompile(`foo`)

	// Append the regexp in Regexps
	regs = multiregexp.Append(regs, re1, re2, re3)

	// Match every regexp with parameter "AND".
	// re1: not match, re2: match, re3: match. It should be false.
	result1 := regs.MatchString("foo", "AND")
	fmt.Println(result1) // => false

	// Check if one of the regexp match with no second parameter.
	// re1: not match, re2: match, re3: match. It should be true.
	result2 := regs.MatchString("foo")
	fmt.Println(result2) // => true

	// Check which regexp in set is matched
	// re1: not match, re2: match, re3: match. It should get [1 2].
	result3 := regs.MatchStringWhich("foo")
	fmt.Println(result3) // => [1 2]
}

About

Multiregexp makes a set of regular expression. And applies some functions for match.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages