I have a scenario where i want to extract the string within bracket after each selected string
- PS=AV_2
- PS=AV_2(AA)
- PS=AV_2(AA),PS=AV_20(BB,ZZ)
- PS=AV_2,PS=AV_20
- PS=AV_2(ZZ),PS=AV_20
eg. input will be PS=AV_2(AA),PS=AV_20(BB,ZZ)
and selectedQues = AV_20 or AV_2
In above only constant part is "PS="
all other string can be anything and any format.
The function should return the string in bracket.
func getStringList(input: String, selectedQues: String ) -> [String] {
// let pattern = "/\\((.*)\\)/" //1. "/\(([^)]+)\)/" //2. "/\\(([^)]+)\\)/)" //3. "([\\w]+(?:,[\\w]+))" some tried regular expression
let pattern = "/\(selectedQues)\\(([^)]+)\\)/g"
let nsString = input as NSString
let regExp = try! NSRegularExpression(pattern: pattern, options: .CaseInsensitive)
let results = regExp.matchesInString(input, options: [], range:NSMakeRange(0, nsString.length))
return results.map { nsString.substringWithRange($0.range)}
}
I am unable to resolve a regular expression for the same. I would be really grateful if someone can help or point to some help.