import Foundation
let pattern = #"(var\s*mapaOportunidade\s*=\s*\{\}\s*;)((?s).*)(var)"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
var mapaOportunidade = {};
mapaOportunidade[113] = 'Promoção Exclusiva p/ você - 06 2016';
mapaOportunidade[112] = '101 a 150 maiores CNs - Evento Mães 2016';
mapaOportunidade[110] = '50 maiores CNs - Evento Mães 2016';
mapaOportunidade[111] = '51 a 100 maiores CNs - Evento Mães 2016';
mapaOportunidade[8] = 'Reinicio';
mapaOportunidade[114] = 'Passe pedido e resgate seus 10 pontos, trocando pelos produtos que quiser!';
mapaOportunidade[90] = 'Ação voltada a ativação de CNs vindas da celula de prospecção e que ainda não colocaram seu 1o pedido';
mapaOportunidade[115] = 'Ação para estimular o relacionamento e venda com consultores que apresentam grande chance de cessação e estão em status i4 e i5';
mapaOportunidade[116] = 'Promo Chegou, Levou! - Ciclo 06/2016';
var mapaTipoOportunidade = {};
function mostraDescricaoOportunidade(combo) {
try {
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
if let firstMatch = regex.firstMatch(in: testString, range: stringRange) {
let result: [String] = (1 ..< firstMatch.numberOfRanges).map { (testString as NSString).substring(with: firstMatch.range(at: $0)) }
print(result)
} else {
print("No matches were found.")
}
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