Skip to content

Go implementation of Regexp::Assemble

License

Notifications You must be signed in to change notification settings

itchyny/rassemble-go

Repository files navigation

rassemble-go

CI Status Go Report Card MIT License release pkg.go.dev

Go implementation of Regexp::Assemble

This is a Go language package for joining regular expressions into a regular expression which matches all strings that any of the arguments matches.

package main

import (
	"fmt"
	"log"

	"github.com/itchyny/rassemble-go"
)

func main() {
	xs, err := rassemble.Join([]string{"abc", "ab", "acbd", "abe"})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(xs) // a(?:b[ce]?|cbd)
}

A command line tool is also provided.

 % go install github.com/itchyny/rassemble-go/cmd/rassemble@latest
 % rassemble abcd abd acd ad
ab?c?d
 % rassemble $(head -n30 /usr/share/dict/words)
A(?:a(?:ni|r(?:on(?:i(?:c(?:al)?|t(?:e|ic)))?|u))|b(?:ab(?:deh|ua))?)?|a(?:a(?:l(?:ii)?|m|rd(?:vark|wolf))?|ba(?:c(?:a(?:te|y)?|i(?:nat(?:e|ion)|s(?:cus|t))|k|tinal(?:ly)?)?)?)?

Bug Tracker

Report bug at Issues・itchyny/rassemble-go - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.