// 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".
import Foundation
func checkPattern(_ pattern: String, _ text: String) -> Bool {
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let range = NSRange(location: 0, length: text.utf16.count)
return regex.firstMatch(in: text, options: [], range: range) != nil
}
let pattern = "b[aeou]y"
print(checkPattern(pattern, "A smart Boy")) // B/b o y
print(checkPattern(pattern, "I want to buy this laptop")) // b u y
print(checkPattern(pattern, "baay"))
print(checkPattern(pattern, "baeouy"))
print(checkPattern(pattern, "baey"))
print(checkPattern(pattern, "This is beauty"))
print(checkPattern(pattern, "A programming book"))
/*
run:
true
true
false
false
false
false
false
*/