NSRegularExpression: Extend named capture group support

Number:rdar://36612942 Date Originated:18-Jan.-2018 10:55 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:11.2
Classification:Feature (New) Reproducible:Not Applicable
iOS 11 introduced named capture support using the -[NSTextCheckingResult rangeWithName:] API, thanks for that.

It would be useful to extract all named capture group matches in a dictionary. I wrote this as an extension on NSString (https://stackoverflow.com/a/48309290/235297) but the code is a bit ugly because there's no API to find out the list of named capture groups. I assume this information is already available internally so please provide one add this readonly property on NSTextCheckingResult:

var namedCaptureGroups: [String : String]? { get }
Returns a dictionary with all matching named capture groups and their matched values.

Alternatively, the `components` property could be changed to a ` [String : String]?` type so it can return arbitrary string keys in the dictionary, not only the predefined NSTextCheckingKey constants.

Steps to Reproduce:

Expected Results:

Actual Results:




Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!