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
Regular expression to validate common Credit Card Numbers
How to iterate over a Map using for loop in Go?
Normal function parameter with variadic function parameter
Golang download image from given URL
Dynamic JSON parser without Struct in Golang
URL parser in Golang
Replace first occurrence of string using Regexp
Golang String Concatenation
How to blur an image in Golang?
Golang Slice interface and array concatenation