Last active
August 29, 2015 14:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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