// NSRegularExpression+Split.swift // // Verbatim ObjC->Swift port originating from https://github.com/bendytree/Objective-C-RegEx-Categories extension NSRegularExpression { func split(_ str: String) -> [String] { let range = NSRange(location: 0, length: str.characters.count) //get locations of matches var matchingRanges: [NSRange] = [] let matches: [NSTextCheckingResult] = self.matches(in: str, options: [], range: range) for match: NSTextCheckingResult in matches { matchingRanges.append(match.range) } //invert ranges - get ranges of non-matched pieces var pieceRanges: [NSRange] = [] //add first range pieceRanges.append(NSRange(location: 0, length: (matchingRanges.count == 0 ? str.characters.count : matchingRanges[0].location))) //add between splits ranges and last range for i in 0..