How might I go about searching/enumerating through an NSString
using a regular expression?
A regular expression such as: /(NS|UI)+(\w+)/g
.
How might I go about searching/enumerating through an NSString
using a regular expression?
A regular expression such as: /(NS|UI)+(\w+)/g
.
If you just want to match some pattern in string, there is a simple way to test Regular Expression with
NSString
:Note, often you'll want ...
In Swift you may write code like this ...
Swift 2
Swift 4
Please take note that Swift 2's
rangeOfString(_:,options:)
and Swift 4'srange(of:options:)
returnRange<String.Index>?
that returns nil if search failedYou need to use
NSRegularExpression
class.Example inspired in the documentation: