Skip to content

Instantly share code, notes, and snippets.

@hyuki

hyuki/lint1.go

Created Apr 16, 2018
Embed
What would you like to do?
簡単なテキストチェッカ(実験中。とりあえず「をを」だけを見つける)
//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

This comment has been minimized.

Copy link
Owner Author

@hyuki 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
You can’t perform that action at this time.