Skip to content

Instantly share code, notes, and snippets.

@ericdke
Last active November 4, 2016 11:37
Show Gist options
  • Select an option

  • Save ericdke/7347705c3e4a205357bf to your computer and use it in GitHub Desktop.

Select an option

Save ericdke/7347705c3e4a205357bf to your computer and use it in GitHub Desktop.
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