import Foundation
let pattern = #"(.*"state":"CA".*"active":true.*)"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive])
let testString = #"""
{"id":1,"last":"Doe","first":"John","location":{"city":"San Francisco","state":"CA","postalCode":"94105"},"active":true}
{"id":2,"last":"Dosdsf","first":"Jane","location":{"city":"San Jose","state":"CA","postalCode":"94110"},"active":false}
{"id":3,"last":"Dodsde","first":"Johnathan","location":{"city":"Los Angeles","state":"WA","postalCode":"90045"},"active":true}
{"id":4,"last":"Dhruvil","first":"Darji","location":{"city":"San Francisco","state":"CA","postalCode":"90304"},"active":false}
{"id":5,"last":"Meghal","first":"Gandhi","location":{"city":"Irvine","state":"WA","postalCode":"94155"},"active":true}
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #""#
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