notes blog about

Regular expressions

// wc counts the number of words in a string
package main

import (
    "fmt"
    "regexp"
)

func main() {
    s := "The quick brown fox."
    ws := regexp.MustCompile(`\s+`)
    words := ws.Split(s, -1) 
    fmt.Printf("%d\n", len(words)) // 4
}