I need to extract string between two \"%\" characters, multiple occurrences can be present in the query string. now am using the following regex, can somebody help to get th
I have written a method for regular express. Your regex is fine. You can test your regexes here . The method is:
func regexInText(regex: String!, text: String!) -> [String] {
do {
let regex = try NSRegularExpression(pattern: regex, options: [])
let nsString = text as NSString
let results = regex.matchesInString(text,
options: [], range: NSMakeRange(0, nsString.length))
return results.map { nsString.substringWithRange($0.range)}
} catch let error as NSError {
print("invalid regex: \(error.localizedDescription)")
return []
}
}
You can call it whereever you want.