import Foundation
let pattern = ##"^\s+\"#{prefix}\.(.+)\":"##
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ##"""
"use strict"
define ->
launchOptions = (prefix) ->
options =
"#{prefix}.businessCredits.businessBudgetFacility": functionDetails: functionId : "be.kbc.businessCredits.businessBudgetFacility", mode: "create"
"#{prefix}.businessCredits.taxPrepaymentPlan": functionDetails: functionId : "be.kbc.businessCredits.taxPrepaymentPlan", mode: "create"
"#{prefix}.credits.privateCreditCardRequest.update": functionDetails: functionId : "be.kbc.credits.privateCreditCardRequest", mode: "update"
"#{prefix}.credits.homeAtOnce": functionDetails: functionId : "be.kbc.credits.homeAtOnce", mode: "createRequest"
"#{prefix}.credits.homeAtOnce.detailRequest": functionDetails: functionId : "be.kbc.credits.homeAtOnce", mode: "detailRequest"
"#{prefix}.credits.homeAtOnce.editRequest": functionDetails: functionId : "be.kbc.credits.homeAtOnce", mode: "editRequest"
"#{prefix}.credits.homeAtOnce.updateRequest": functionDetails: functionId : "be.kbc.credits.homeAtOnce", mode: "updateRequest"
"#{prefix}.credits.budgetfacilitylight": functionDetails: functionId : "be.kbc.credits.budgetFacilityLight", mode: "create"
"#{prefix}.credits.loaRequest": functionDetails: functionId : "be.kbc.credits.loaRequest", mode: "create"
"#{prefix}.credits.loaRequest.update": functionDetails: functionId : "be.kbc.credits.loaRequest", mode: "update"
"#{prefix}.doccle.doccleAccount": functionDetails: functionId : "be.kbc.doccle.doccleAccount", mode: "create"
"#{prefix}.esigning.esigning": functionDetails: functionId : "be.kbc.esigning.esigning", mode: "create"
"#{prefix}.esigning.esigning.createBundle": functionDetails: functionId : "be.kbc.esigning.esigning", mode: "createBundle"
"#{prefix}.home.dinoHomeInsurance": functionDetails: functionId : "be.kbc.home.dinoHomeInsurance", mode: "create"
"#{prefix}.home.energyRenovationAdvice": functionDetails: functionId : "be.kbc.home.era", mode: "create"
"#{prefix}.insurances.smallProducts": functionDetails: functionId : "be.kbc.insurances.smallProducts", mode: "create"
"#{prefix}.insurances.smallproducts.external": functionDetails: functionId : "be.kbc.insurances.smallProducts", mode: "create"
"#{prefix}.insurances.insurancesUpsell": functionDetails: functionId : "be.kbc.insurances.insurancesUpsell", mode: "create"
"#{prefix}.investments.buycooperativeshares": functionDetails: functionId : "be.kbc.investments.buyCooperativeShares", mode: "create"
"#{prefix}.savings.acceptSavingsAccount": functionDetails: functionId : "be.kbc.savings.acceptSavingsAccount", mode: "create"
"#{prefix}.savings.manageAccountInsurance": functionDetails: functionId : "be.kbc.savings.manageAccountInsurance", mode: "create"
"#{prefix}.savings.manageAccountInsurance.delete": functionDetails: functionId : "be.kbc.savings.manageAccountInsurance", mode: "delete"
"#{prefix}.savings.openSavingsAccount": functionDetails: functionId : "be.kbc.savings.openSavingsAccount", mode: "create"
"#{prefix}.savings.settleSavingsAccount": functionDetails: functionId : "be.kbc.savings.settleSavingsAccount", mode: "create"
"#{prefix}.payments.businessAccountRequest": functionDetails: functionId : "be.kbc.payments.businessAccountRequest", mode: "create"
"#{prefix}.payments.cardPhoto": functionDetails: functionId : "be.kbc.payments.cardPhoto", mode: "create"
"#{prefix}.payments.preaccountrequest": functionDetails: functionId : "be.kbc.payments.preAccountRequest", mode: "create"
"#{prefix}.payments.privateAccountRequest": functionDetails: functionId : "be.kbc.payments.privateAccountRequest", mode: "create"
"#{prefix}.payments.businessCreditCardRequest": functionDetails: functionId : "be.kbc.payments.businessCreditCardRequest", mode: "create"
"#{prefix}.payments.preCardRequest": functionDetails: functionId : "be.kbc.payments.preCardRequest", mode: "create"
"#{prefix}.payments.preCardRequest.createReplacement": functionDetails: functionId : "be.kbc.payments.preCardRequest", mode: "createReplacement"
"#{prefix}.vehicle.dinoCarInsurance": functionDetails: functionId : "be.kbc.vehicle.dinoCarInsurance", mode: "create"
"#{prefix}.vehicle.privateLease": functionDetails: functionId : "be.kbc.vehicle.privateLease", mode: "create"
"#{prefix}.vehicle.privateLease.update": functionDetails: functionId : "be.kbc.vehicle.privateLease", mode: "update"
# Note: the deeplinks below are for local development testing only, the won't be available in the pillars
# coffeelint: disable=no_backticks
`//>>includeStart("local", pragmas.local)`
options["#{prefix}.credits.genericRequest"] = functionDetails: functionId : "be.kbc.credits.genericRequest", mode: "create"
options["#{prefix}.credits.genericRequest.continue"] = functionDetails: functionId : "be.kbc.credits.genericRequest", mode: "continue"
`//>>includeEnd("local")`
return options
return launchOptions
"""##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let matches = regex.matches(in: testString, range: stringRange)
var result: [[String]] = []
for match in matches {
var groups: [String] = []
for rangeIndex in 1 ..< match.numberOfRanges {
let nsRange = match.range(at: rangeIndex)
guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue }
let string = (testString as NSString).substring(with: nsRange)
groups.append(string)
}
if !groups.isEmpty {
result.append(groups)
}
}
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