ios - How to use NSRegularExpression in Swift 2.0 in xcode 7 -


//the error here let regex = nsregularexpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: nil, error: nil)

//the error is:***

cannot find initializer type nsregularexpression accept argument of type (pattern: string,ption:nil,error:nil)

there 2 changes regards syntax in swift 2.0: (1) wrap call in try ... catch block instead of supplying error parameter; , (2) options should set, not numerical or of individual options.

in case code should this:

do {     let regex = try nsregularexpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: []) } catch let error nserror {     print(error.localizeddescription) } 

if know pattern succeeds, can shorten this:

let regex = try! nsregularexpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: []) 

now if want set options pattern, can this:

let regex = try! nsregularexpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: [.caseinsensitive, .anchorsmatchlines]) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -