import Foundation
let pattern = #"(url\\?":\\?")(?!http|https)(.*?)""#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
"{"blocks":[{"key":"dimrp","text":"bratwurst currywurst ","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":9,"key":0},{"offset":10,"length":10,"key":1}],"data":{}}],"entityMap":{"0":{"type":"LINK","mutability":"MUTABLE","data":{"url":"http://www.google.com","targetOption":"_blank"}},"1":{"type":"LINK","mutability":"MUTABLE","data":{"url":"www.berlin.de","targetOption":"_blank"}}, "2":{"type":"LINK","mutability":"MUTABLE","data":{"url":"javascript:alert(101)","targetOption":"_blank"}}, "3":{"type":"LINK","mutability":"MUTABLE","data":{"url":"https//www.google.com","targetOption":"_blank"}}}}"
{"header":{"account_id":"b05f9df8-cd3b-4b30-b57b-5b45ffaac62f","aggregate_id":"9e168575-4127-4c69-beaf-f117dbab87e8","aggregate_name":"GUIDES","aggregate_root_id":"9e168575-4127-4c69-beaf-f117dbab87e8","aggregate_version":32,"correlation_id":"d89b000e-9b9c-4799-881a-ea4547f922d3","msg_id":"0955de48-8488-4989-a86f-e19c8bbf739a","msg_key":"9e168575-4127-4c69-beaf-f117dbab87e8","msg_schema_name":"EDIT_TEXT_IN_TEXT_WIDGET","msg_schema_version":1,"msg_timestamp":1557938204180,"msg_topic":"MICHAEL.TOPIC_COMMANDS","source_system_instance_id":"240b62d7-7e6e-4c4a-8f5c-1c816b16012c","source_system_name":"BynderAPI_V2__development__node_http_service_skel__0.0.1__240b62d7-7e6e-4c4a-8f5c-1c816b16012c","user_id":"ab851f80-916b-4e12-a49c-b70e6ab1f817"},"payload":{"chapter_id":"cc1403b7-302a-4d0d-8a95-96b99a20c306","page_id":"965f6828-6878-4795-81b6-066c207b2ca9","section_id":"3e223fc9-78d6-4a60-9d27-2224d7cd4a35","widget_id":"e976646e-0bed-4c12-9893-9688d6c89dbe","widget_type":"text","widget_text":"{\"blocks\":[{\"key\":\"bg6c2\",\"text\":\"Helllo World \",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[{\"offset\":0,\"length\":6,\"key\":0},{\"offset\":8,\"length\":5,\"key\":1}],\"data\":{}}],\"entityMap\":{\"0\":{\"type\":\"LINK\",\"mutability\":\"MUTABLE\",\"data\":{\"url\":\"https://www.bynder.com\",\"targetOption\":\"_blank\"}},\"1\":{\"type\":\"LINK\",\"mutability\":\"MUTABLE\",\"data\":{\"url\":\"www.google.com\",\"targetOption\":\"_blank\"}}}}","command_time":"2019-05-15T16:36:44.166Z","guide_id":"9e168575-4127-4c69-beaf-f117dbab87e8","guide_version":32}}
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$1https://$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