import Foundation
let pattern = ##"""
(?# Patrón de nombre multivariado)
\bJorge\s+((Alberto|A\.?)\s+)?/?(?P<Apellido>G[óo]mez)(\s+(Prada|P\.?))?\b
"""##
let regex = try! NSRegularExpression(pattern: pattern, options: [.caseInsensitive, .allowCommentsAndWhitespace])
let testString = #"""
(1)Jorge Alberto Gómez Prada = (2)Jorge Gómez = (3)Jorge A Gómez = (4)Jorge A. Gómez P.
(5)(Jorge GOMEZ P.a) ... (6)Alberto jorge GÓMEZ (7)Jorge /Gómez
(8)>>Jorge A
Gómez P<< (9)Jorge Gómez Pradas (10)JJorge Gómez (11) Luis Jorge Gómeza
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"Amparo \g<Apellido>"#
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