There are 2 changes with regards to the syntax in Swift 2.0: (1) you wrap the call in a try ... catch
block instead of supplying an error
parameter; and (2) options
should be a Set
, not a numerical or
of the individual options.
In your case the code should look like this:
do {
let regex = try NSRegularExpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: [])
} catch let error as NSError {
print(error.localizedDescription)
}
If you know that your pattern always succeeds, you can shorten it like this:
let regex = try! NSRegularExpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: [])
Now if you want to set options to your pattern, you can do this:
let regex = try! NSRegularExpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: [.CaseInsensitive, .AnchorsMatchLines])