Regular expression to extract all Non-Alphanumeric Characters from a String
Example
package main
import (
"fmt"
"regexp"
)
func main() {
str1 := "We @@@Love@@@@ #Go!$! ****Programming****Language^^^"
re := regexp.MustCompile(`[^a-zA-Z0-9]+`)
fmt.Printf("Pattern: %v\n", re.String()) // print pattern
fmt.Println(re.MatchString(str1)) // true
submatchall := re.FindAllString(str1, -1)
for _, element := range submatchall {
fmt.Println(element)
}
}
Output
Pattern: [^a-zA-Z0-9]+
true
@@@
@@@@ #
!$! ****
****
^^^
Most Helpful This Week
Replace any non-alphanumeric character sequences with a dash using Regex
Replace first occurrence of string using Regexp
Regular expression for matching HH:MM time format in Golang
Regular expression to extract domain from URL
How to remove symbols from a string in Golang?
Split a string at uppercase letters using regular expression in Golang