import Foundation
let pattern = #"([+0]?[06]?)(?&sep)(36)?(?&sep)(?P<aera>1|[2-9][0-9])(?&sep)(?P<num>\d{3})(?&sep)(\d{2})(?'sep'[\)\(-\/\.x ]*){2}"#
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let testString = #"""
+36 20 800 8848
36 1 267-5260
+36 1 267 5260
+36 24 415 351
06 (24) 415 351
6(1)415 3510
00361-267-5260
0036-1-267-5260
0036-1-267-52-60
208008848
20800 88-48
00 34 800 828
((06)|[\+0]{0,2}\s*36)
[+0]{0,2}(?&sep)36
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$3$4$5$6"#
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