Last active
November 4, 2016 11:37
-
-
Save ericdke/7347705c3e4a205357bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| extension String { | |
| func matchesBetweenPairs(of char: Character) -> [String] { | |
| let str = "(?<=\\\(char))[^ ]+(?=\\\(char))" | |
| let regex = try! NSRegularExpression(pattern: str, options: .caseInsensitive) | |
| let rng = NSRange(location: 0, length: self.characters.count) | |
| let matches = regex.matches(in: self, options: [], range: rng) | |
| return matches.map { (self as NSString).substring(with: $0.range) } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment