Regular expression to split string on white spaces
Example
package main
import (
"fmt"
"regexp"
)
func main() {
str1 := "Split String on \nwhite \tspaces."
re := regexp.MustCompile(`\S+`)
fmt.Printf("Pattern: %v\n", re.String()) // Print Pattern
fmt.Printf("String contains any match: %v\n", re.MatchString(str1)) // True
submatchall := re.FindAllString(str1, -1)
for _, element := range submatchall {
fmt.Println(element)
}
}
Output
Pattern: \S+
String contains any match: true
Split
String
on
white
spaces.
Most Helpful This Week
How to replace emoji characters in string using regex in Golang?
How to extract text from between html tag using Regular Expressions in Golang?
Regular expression to extract date(YYYY-MM-DD) from string
Regular expression to extract all Non-Alphanumeric Characters from a String
Regular expression to extract filename from given path in Golang
Regular expression to validate common Credit Card Numbers