package main import ( "fmt" "regexp" ) func main() { var pattern = "^hello world$" var input = "hello world" if matched, _ := regexp.MatchString(pattern, input); matched { fmt.Println("String matched the pattern") } else { fmt.Println("String did not match the pattern") } }
package main import ( "fmt" "regexp" ) func main() { var pattern = "^hello [a-z]+ world$" var input = "hello there world" if matched, _ := regexp.MatchString(pattern, input); matched { fmt.Println("String matched the pattern") } else { fmt.Println("String did not match the pattern") } }In this example, we are using the MatchString method to match a string that contains alphabets between "hello" and "world." The pattern "^hello [a-z]+ world$" matches any lowercase alphabets between "hello" and "world". Since our input string "hello there world" matches this pattern, the function will return true, and the output will be "String matched the pattern." Package: `regexp`