import Foundation
let pattern = #"(?|(\[[\"]?.+?[\"]?\])(=>)\R\s*|(?<=\(0\) )(\{)\R\s*(\}))"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = ##"""
object(Symfony\Component\HttpFoundation\Request)#250 (21) {
["attributes"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#253 (1) {
["parameters":protected]=>
array(5) {
["_controller"]=>
object(Closure)#239 (2) {
["static"]=>
array(1) {
["app"]=>
object(Silex\Application)#14 (8) {
["providers":protected]=>
array(5) {
[0]=>
object(Silex\Provider\HttpKernelServiceProvider)#17 (0) {
}
[1]=>
object(Silex\Provider\RoutingServiceProvider)#26 (0) {
}
[2]=>
object(Silex\Provider\ExceptionHandlerServiceProvider)#36 (0) {
}
[3]=>
object(Silex\Provider\TwigServiceProvider)#38 (0) {
}
[4]=>
object(Euskadi31\Silex\Provider\CorsServiceProvider)#54 (0) {
}
}
["booted":protected]=>
bool(true)
["values":"Pimple\Container":private]=>
array(37) {
["request.http_port"]=>
int(80)
["request.https_port"]=>
int(443)
["debug"]=>
bool(true)
["charset"]=>
string(5) "UTF-8"
["logger"]=>
NULL
["resolver"]=>
object(Symfony\Component\HttpKernel\Controller\ControllerResolver)#307 (1) {
["logger":"Symfony\Component\HttpKernel\Controller\ControllerResolver":private]=>
NULL
}
["argument_metadata_factory"]=>
object(Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory)#301 (0) {
}
["argument_value_resolvers"]=>
array(5) {
[0]=>
object(Silex\AppArgumentValueResolver)#298 (1) {
["app":"Silex\AppArgumentValueResolver":private]=>
*RECURSION*
}
[1]=>
object(Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver)#295 (0) {
}
[2]=>
object(Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestValueResolver)#292 (0) {
}
[3]=>
object(Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver)#289 (0) {
}
[4]=>
object(Symfony\Component\HttpKernel\Controller\ArgumentResolver\VariadicValueResolver)#286 (0) {
}
}
"""##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"\1 \2"#
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