import Foundation
let pattern = #"^(?!acteur:).*(*SKIP)(*F)|(?:^acteur:\h+|\h+)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
acteur: 634, 681, 731
inbob: -1
mention:
Il n'est pas distingué
acteur: 731
lieu:
editeur: Les étoiles de la chanson
collection:
numed:
nbv:
nbp:
date: [1934]
date2: 1934
(:remarque:Deuxième vérification faite : ok:)");
type:
inbob: -1
mention:
Comme un moineau
acteur: 634, 681, 731
lieu:
editeur: Les étoiles de la chanson
collection:
numed:
nbv:
nbp:
date: [1930]
date2: 1930
(:remarque::)");
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"Acteur."#
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