text := "The quick brown fox jumps over the lazy dog" regex := regexp.MustCompile(`\w+`) matches := regex.FindAllStringSubmatch(text, -1) fmt.Println(matches)
[[The] [quick] [brown] [fox] [jumps] [over] [the] [lazy] [dog]]
text := "Email me at [email protected] or [email protected]" regex := regexp.MustCompile(`(\w+)@(\w+\.\w+)`) matches := regex.FindAllStringSubmatch(text, -1) fmt.Println(matches)
[[[email protected] john example.com] [[email protected] jane example.com]]In this example, we use the regular expression `(\w+)@(\w+\.\w+)` to match email addresses in the text. The `(\w+)` and `(\w+\.\w+)` subexpressions capture the local and domain parts of each email address, respectively. This example also uses the "regexp" package.