import Foundation
let pattern = #"^:Quote_two \([\s\S]+?[\r\n]+\)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
:Quote_one (
:parent (QUOTES_ALL)
:id ("abc1234")
:display_name ("Quote Number One")
:children (
: (Quotes)
: (Sayings)
)
)
:Quote_two (
:parent (QUOTES_ALL)
:uuid ("def456")
:display_name ("Quote Number Two")
:Address (
: (
:num ("1234")
:city ("Dallas")
:state ("TX")
)
)
:Numbers (
: (
:num1 ("345-222-1111")
:num2 (123)
:num3 (456)
)
)
:Names (
: ("Test")
: ("Test2")
: ("Test3")
)
)
:Quote_three (
:parent (QUOTES_ALL)
:id ("xyz1234")
:display_name ("Quote Number Three")
:children (
: (Quotes)
: (Sayings)
)
)
"""#
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