import Foundation
let pattern = #"by([^(b(?>y))])+"#
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let testString = #"zzzzzzzzzzzzzzzzzzeererezzz By LITE-ON!Model: PA-1121-12H, PA-1121-12R!Series: PPP017L!HP Part No.: 316688-001, 394900-001, 393946-001!!By HIPRO!Model: HP-OW121F13!Series: PPP017H!HP Part No.: 316688-002!!By Fordgood!Model: 0309A18120!Series: PPP017S!HP Part No.: 316688-003 !Replace with HP Spare No.: 317188-001!Compatible HP Spare No.: 350775-001!!Input: 110-240V~ 2.5A, 50-60Hz!Output: 18.5V 6.5A 120W!Connecter size: Int. Diameter: 2.50mm Ext. Diameter: 5.50mm Length : 14.00mm!!Dimension: 168 x 62 x 37 mm!!*For use with Presario 3000xx notebook series.!!**Please take note, 3 wire AC power cord not included.!!/by([^(b(?>y))])+/gi"#
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