package main import ( "fmt" "regexp" ) func main() { sentence := "The quick brown fox jumped over the lazy dog" word := "the" re := regexp.MustCompile(word) found := re.FindAllString(sentence, -1) fmt.Println(found) }
package main import ( "fmt" "regexp" ) func main() { str := "There are 123 apples in the basket" re := regexp.MustCompile("[0-9]+") found := re.FindAllString(str, -1) fmt.Println(found) }This code searches for all occurrences of numbers in a given string. The regular expression "[0-9]+" matches one or more digits. The "Regexp.FindAllString" method is then used to find all matches and return them as a slice of strings. The "regexp" package is a standard library in Go, meaning it is included with every installation of the language.