package main import ( "fmt" "regexp" ) func main() { str := "Hello, World!" pattern := "World" matched, _ := regexp.MatchString(pattern, str) fmt.Println(matched) // true }
package main import ( "fmt" "regexp" ) func main() { str := "John Doe (36 years old)" pattern := "(\\w+) (\\w+) \\((\\d+) years old\\)" matched := regexp.MustCompile(pattern).FindStringSubmatch(str) fmt.Println(matched[1]) // John fmt.Println(matched[2]) // Doe fmt.Println(matched[3]) // 36 }This example uses the FindStringSubmatch function to match the "John Doe (36 years old)" string to the pattern "(\\w+) (\\w+) \\((\\d+) years old\\)". It then extracts the matched groups (John, Doe, and 36) from the result. Package library: regexp.