import Foundation
let pattern = #"model: ([^\n]+)(.*)bitmap [^\n]+"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .dotMatchesLineSeparators])
let testString = ##"""
# model: pmy0_footr015
filedependancy Unknown
newmodel pmy0_footr015
setsupermodel pmy0_footr015 NULL
classification Character
setanimationscale 1.0
beginmodelgeom pmy0_footr015
node dummy pmy0_footr015
parent NULL
endnode
node trimesh pmy0_footr015g
parent pmy0_footr015
position 0.0 0.0 0.0
orientation 1.0 0.0 0.0 0.0
bitmap pmh0_footr050
verts 15
-0.0378169 -0.00381612 0.00857995
"""##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"model: $1$2bitmap $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