Created
May 20, 2020 23:00
-
-
Save robertmryan/138ffea5603625830d0970b3022fefdf to your computer and use it in GitHub Desktop.
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
extension String { | |
func matches(of regex: String, options: NSRegularExpression.Options = []) throws -> [String] { | |
try NSRegularExpression(pattern: regex, options: options) | |
.matches(in: self, range: NSRange(startIndex..., in: self)) | |
.compactMap { Range($0.range, in: self) } | |
.map { String(self[$0]) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then you can do things like:
or, the following will do a case insensitive search