import Foundation
let pattern = #"select\[([^\s]*(?<param>[a-z0-9]+)[^,\s]*)*\]"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
select[ 1, 22 ,word, two words ]
attempting to load capture group with (numerics or alpha-num options) from comma separated list ignoring leading/trailing whitespace of each param but preserving space between words (ie "two words).
results like
param1: "1"
param2: "22"
param3: "word"
param4: "two words"
once thats sorted, would liek to handle optional single quote ' around parameters.
Thanks for the consideration
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"\1"#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression