import Foundation
let pattern = #"^[^\d+-]*([+-]?)\s*+(\d++(?:\.\d+)?)|\G[^\d+-]*(?:([+-])\s*+((?2))|((?2)))|[+-]++|[^+-]++"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
Lorem ipsum dolor sit amet.
Nullam 000 ut finibus 111 lectus.
Praesent 222 eu 333 sem lorem.
Fusce elementum 444 gravida 555 luctus.
Sed non "accumsan" - 777 lorem!
1. Vivamus at mauris mi.[1]
2. Duis ac faucibus elit.[2][3]
3. Sed sed 'tempor' diam.[4,5]
Vivamus 2024-12-21 tincidunt tristique dolor.
"Morbi vel blandit augue?"
Morbi eu tortor 25.25 ligula.
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"${2:+$1$2}${3:+$3$4}${5:++$5}"#
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