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)?)?)?)?
Report bug at Issues・itchyny/rassemble-go - GitHub.
itchyny (https://github.com/itchyny)
This software is released under the MIT License, see LICENSE.