import Foundation
let pattern = #" \n {24}"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
RAW DATA
26/11/15 26/11/15 1314 NEFT : CMS364134568 - CRE
DIT CARD OPERATIONS
26/11/15 26/11/15 1314 Cash Deposit
27/11/15 27/11/15 1314 NEFT : CMS364860637 - CRE
DIT CARD OPERATIONS
27/11/15 27/11/15 1314 Cash Deposit
30/11/15 30/11/15 1314 NEFT : CMS365476895 - CRE
DIT CARD OPERATIONS
30/11/15 30/11/15 1314 NEFT : CMS365573866 - CRE
DIT CARD OPERATIONS
30/11/15 30/11/15 1314 NEFT : CMS365623059 - CRE
DIT CARD OPERATIONS
"""#
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