Created
November 20, 2014 11:38
-
-
Save hebertialmeida/be0b689bf0370d5a2764 to your computer and use it in GitHub Desktop.
Given a dictionary of words, return an array of the words whose match. (i.e. pattern "c.t" match with "cat", "cut", etc. because the dot notation stand for ANY character). Swift implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var words = ["Cat", "Cot", "Brazil", "Cut", "cat", "Apple", "Watch"] | |
var filter = [String]() | |
for word in words { | |
if let match = word.rangeOfString("(C|c)(.*)t", options: .RegularExpressionSearch) { | |
filter.append(word) | |
} | |
} | |
println(filter) | |
//returns [Cat, Cot, Cut, cat] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment