In Swift, what is a simple way to see if a string matches a pattern?
Pseudocode examples:
if string matches pattern ...
if string =~ pattern ...
(I have read the Swift docs and haven't seen a regex capability. I've read about adding a new =~
operator which is a good idea yet more complex than I'd like because this is for a teaching project. I have tried rangeOfString
but get the error: 'String' does not have a member 'rangeOfString'. I am looking for a Swift solution, i.e. not typing NSRegularExpression. I do not need to do anything with the match result data.)