package main
import (
"fmt"
"regexp"
)
// b[aeou]y: This pattern looks for strings that match the following:
// b: The letter "b".
// [aeou]: Any single character that is either "a", "e", "o", or "u".
// y: The letter "y".
func checkPattern(pattern, text string) bool {
re, err := regexp.Compile(`(?i)` + pattern)
if err != nil {
return false
}
return re.MatchString(text)
}
func main() {
pattern := "b[aeou]y"
fmt.Println(checkPattern(pattern, "A smart boy")) // b o y
fmt.Println(checkPattern(pattern, "I want to buy this laptop")) // b u y
fmt.Println(checkPattern(pattern, "baay"))
fmt.Println(checkPattern(pattern, "baeouy"))
fmt.Println(checkPattern(pattern, "baey"))
fmt.Println(checkPattern(pattern, "This is beauty"))
fmt.Println(checkPattern(pattern, "A programming book"))
}
/*
run:
true
true
false
false
false
false
false
*/