[Solved] Regular Expression generation in Swift [duplicate]
You could do something like this : let str = “_h Hello _h _h World _h” let range = NSRange(str.startIndex…, in: str) let regex = try! NSRegularExpression(pattern: “(?<=_h).+?(?=_h)”) let matches = regex.matches(in: str, range: range) let results: [String] = matches.compactMap { match in let subStr = String(str[Range(match.range, in: str)!]).trimmingCharacters(in: .whitespacesAndNewlines) return subStr.isEmpty ? nil : … Read more