import Foundation
let pattern = #"^([^""].+? .+?\.exe)(?!$)"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive])
let testString = #"""
C:\Program Files (x86)\InstallShield Installation Information\{50033799-D5D3-4759-9ABD-589AD04F33C1}\setup.exe -runfromtemp -l0x0009 -removeonly
C:\Program Files (x86)\Some Directory\Foo.exe
C:\SomePath\WithoutSpaces\Bar.exe -baz
"C:\Some Path\With Spaces\Qux.exe" -quux
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #""$1""#
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