04.4.3 高级的正则表达式示例
package main import ( "bufio" "fmt" "io" "os" "regexp" "strings" "time" ) func main() { arguments := os.Args if len(arguments) ==1 { fmt.Println("Please provide one text file to process") os.Exit(1) } fileName := arguments[1] f, err := os.Open(fileName) if err != nil { fmt.Printf("error opening file %s ",err) os.Exit(1) } defer f.Close() notAmatch := 0 r := bufio.NewReader(f) for{ line, err := r.ReadString('\n') if err == io.EOF { break } else if err != nil{ fmt.Printf("error reading file %s,",err) }

Last updated