regex to get string between two % characters

Viewed 7975

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 the exact Regax format.

let query =  "Hello %test% ho do you do %test1%"
let regex = try! NSRegularExpression(pattern:"%(.*?)%", options: [])

  if let results = regex?.matchesInString(query, options: .Anchored,  range: NSMakeRange(0,query.characters.count)){
    for match in results{
         }
      }
2 Answers
Related