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
How to remove symbols from a string in Golang?
How to count number of repeating words in a given String?
Find out how many logical processors used by current process
Golang Slice vs Map Benchmark Testing
How to get the current date and time with timestamp in local and other timezones ?
How to fix race condition using Atomic Functions in Golang?
Example of Sscan vs Sscanf vs Sscanln from FMT Package
Example: Stack and Caller from RUNTIME package
How to delete or remove element from a Map?
Replace numbers by zero from string