Skip to content

Instantly share code, notes, and snippets.

@rjeczalik
Last active August 29, 2015 14:07
Show Gist options
  • Save rjeczalik/1dfbc21e838083b177f9 to your computer and use it in GitHub Desktop.
Save rjeczalik/1dfbc21e838083b177f9 to your computer and use it in GitHub Desktop.
re2match - command line tool matching re2-like regexes on data read from stdin
package main
import (
"bufio"
"fmt"
"os"
"regexp"
)
const usage = "usage: echo TEXT | re2match REGEXP"
func die(v ...interface{}) {
for _, v := range v {
fmt.Fprintln(os.Stderr, v)
}
os.Exit(1)
}
func main() {
if len(os.Args) != 2 {
die(usage)
}
if ok, err := regexp.MatchReader(os.Args[1], bufio.NewReader(os.Stdin)); err != nil {
die(err)
} else if !ok {
die()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment