Reputation: 11493
Is it possible to check for multiple variations of a string using a single Regular Expressions?
I want find matches of the following two string variations in a longer string.
E.g.
"Do some clean up every year"
"Plan yearly clean up"
Currently my regex pattern looks like the following, working only for one specific variation
var pattern = "yearly"
var error: NSError?
var regularExpression = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error)!
let matchingItems = regularExpression.matchesInString(entryString, options: nil, range:NSMakeRange(0, countElements(entryString)))
Can the matching of both cases ("yearly" + "every year") be combined using one Regular Expression or do I need two separate Regular Expressions for this?
Upvotes: 1
Views: 1569
Reputation: 67968
var pattern = "yearly|(?:every year)"
You can try this way using |
or operator.
Upvotes: 2