Skip to content

Instantly share code, notes, and snippets.

@hyuki
Created April 16, 2018 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/b98fe9f69c2cb403cebcb992d2ae0c9e to your computer and use it in GitHub Desktop.
Save hyuki/b98fe9f69c2cb403cebcb992d2ae0c9e to your computer and use it in GitHub Desktop.
簡単なテキストチェッカ(実験中。とりあえず「をを」だけを見つける)
//usr/bin/env go run $0 $@ ; exit
package main
import (
"bufio"
"fmt"
"os"
"regexp"
)
func match(re string, line string) []string {
return regexp.MustCompile(re).FindStringSubmatch(line)
}
func main() {
stdin := bufio.NewScanner(os.Stdin)
for linenumber := 1; stdin.Scan(); linenumber++ {
line := stdin.Text()
if m := match(`^(.*?)(をを)(.*?)$`, line); m != nil {
fmt.Printf("%d: %s【%s】%s\n", linenumber, m[1], m[2], m[3])
}
}
}
@hyuki
Copy link
Author

hyuki commented Apr 16, 2018

$ cat file.txt
これははどうしますか。
これををどうしようか。
$ go run lint1.go < file.txt
2: これ【をを】どうしようか。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment