Split a string at uppercase letters using regular expression in Golang
Example
package main
import (
"fmt"
"regexp"
)
func main() {
str1 := "Hello X42 I'm a Y-32.35 string Z30"
re := regexp.MustCompile(`[A-Z][^A-Z]*`)
fmt.Printf("Pattern: %v\n", re.String()) // Print Pattern
submatchall := re.FindAllString(str1, -1)
for _, element := range submatchall {
fmt.Println(element)
}
}
Output
Pattern: [A-Z][^A-Z]*
Hello
X42
I'm a
Y-32.35 string
Z30
Most Helpful This Week
How to play and pause execution of goroutine?
Find length of Channel, Pointer, Slice, String and Map
Example: Arrays of Arrays, Arrays of Slices, Slices of Arrays and Slices of Slices
How to Decode or Unmarshal bi-dimensional array of integers?
How to create thumbnail of an image?
How to create Map using the make function in Go?