import Foundation
let pattern = ##"^\s*#.*$"##
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ##"""
#Processed by Id: cwm.py,v 1.197 2007/12/13 15:38:39 syosi Exp
# using base http://www.prodigi.eu/instances
# Notation3 generation by
# notation3.py,v 1.200 2007/12/11 21:18:08 syosi Exp
# Base was: http://www.prodigi.eu/instances
@prefix : </ac-schema#> .
@prefix ins: </instances#> .
@prefix olanet: <http://www.ibermaticaindustria.com/soluciones/planta-mes-olanet#> .
@prefix plm: <http://hms.ifw.uni-hannover.de/#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
ins:everyone a <http://xmlns.com/foaf/0.1/Group>;
:canSee ins:public;
rdfs:member <http://127.0.0.1/OslcOlanetProvider/api/producer/01>,
#abul maal abdul muhit
[...]
"""##
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