replexp/main.go
von paedubucher- SNIPPET_DESC:
- REPL für reguläre Ausdrücke in Go
- SNIPPET_CREATION_TIME:
- 19.06.2022 16:52:46
- SNIPPET_PRUNE_TIME:
- Unendlich
- SNIPPET_TEXT:
-
- package main
- import (
- "bufio"
- "fmt"
- "io"
- "os"
- "regexp"
- )
- func main() {
- if len(os.Args) < 2 {
- fmt.Fprintf(os.Stderr, "usage: %s [regexp]\n", os.Args[0])
- os.Exit(1)
- }
- pattern := os.Args[1]
- input := bufio.NewReader(os.Stdin)
- var line []byte
- var err error
- for ; err != io.EOF; line, err = input.ReadBytes('\n') {
- if len(line) == 0 {
- continue
- }
- if ok, _ := regexp.Match(pattern, line); ok {
- fmt.Print(string(line))
- }
- }
- }
Quellcode
Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN