package main import ( "regexp" "fmt" ) func main() { re := regexp.MustCompile(`^Hello.*World$`) fmt.Println(re.MatchString("Hello, how are you? World!")) // true fmt.Println(re.MatchString("Hi there, World!")) // false }
package main import ( "regexp" "fmt" ) func main() { re := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`) fmt.Println(re.MatchString("[email protected]")) // true fmt.Println(re.MatchString("[email protected]")) // false }In this example, we define a regular expression pattern using the `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$` pattern. This pattern matches email addresses that follow the common format. We then use the `MatchString()` method to check if different strings match this pattern. The package library for Go regexp is built-in to the standard library and does not require any additional installation or downloads.