import Foundation
let pattern = #"((object|inherited) \w+:[ ](TMgDBEdit).*?)((Color = clInactiveCaptionText\n)|(\n\s+end))"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive, .dotMatchesLineSeparators])
let testString = #"""
object Ed_PRO_ST_DESCRICAO: TMgDBEdit
Left = 132
Top = 81
Width = 675
Height = 21
AutoSize = False
Color = clInactiveCaptionText
DataField = 'PRO_ST_DESCRICAO'
DataSource = Dm_AdmInt.Ds_Produtos_
TabOrder = 4
OnChange = Ed_PRO_ST_DESCRICAOChange
OnExit = Ed_PRO_ST_DESCRICAOExit
OnKeyPress = Ed_PRO_ST_DESCRICAOKeyPress
Password = False
end
object Ed_PRO_ST_NARRATIVA1: TMgDBMemo
Left = 132
Top = 157
Width = 675
Height = 78
DataField = 'PRO_ST_NARRATIVA'
DataSource = Dm_AdmInt.Ds_Produtos_
MaxLength = 500
ScrollBars = ssVertical
TabOrder = 7
end
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"\1ParentFont = True\n"#
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