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 convert Colorful PNG image to Gray-scale?
How can we reverse a simple string in Go?
Various examples of Carbon date-time package in Golang
Find length of Channel, Pointer, Slice, String and Map
How to Convert string to float type in Go?
How to create a photo gallery in Go?
How to read names of all files and folders in current directory?
How to import structs from another package in Go?
How to split a string on white-space?
How to remove symbols from a string in Golang?