import Foundation
let pattern = #"^_.*(*SKIP)(*F)|\[\[|]]"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ###"""
## [[zoom]] _[v]_
>[[move]] | [[very]] | [[quickly]]
__Synonyms__: [[buzz]] | [[dart]] | [[dash]] | [[dive]] | [[flash]] | [[fly]] | [[hum]] | [[hurtle]] | outstrip | [[rip]] | [[rocket]] | [[rush]] | [[shoot]] | [[shoot]] up | [[skyrocket]] | [[speed]] | [[streak]] | [[surge]] | [[tear]] | [[whirl]] | [[whiz]] | [[zip]]
__Concepts__: [[ACTIONS - MOTION#move oneself quickly (150)\|move oneself quickly]]
__Antonyms__: decelerate, [[slow]]
## [[zip]] _[n]_
>[[enthusiasm]], [[energy]]
__Synonyms__: brio | [[drive]] | [[get]]-upand-[[go]] | [[go]] | [[gusto]] | [[life]] | liveliness | [[oomph]] | [[pep]] | [[pizzazz]] | [[punch]] | [[sparkle]] | [[spirit]] | [[verve]] | [[vigor]] | vim | [[vitality]] | [[zest]] | [[zing]]
__Concepts__: [[LIFE FORMS - GENERAL CHARACTERISTICS#personality (411)\|personality]], [[STATES - ABSTRACT#behavior (633)\|behavior]]
__Antonyms__: [[apathy]], enervation, [[idleness]], [[laziness]], [[lethargy]]
## [[zip]] _[v]_
>[[move]] | [[about]] | [[quickly]]
__Synonyms__: [[bustle]] | [[dash]] | [[flash]] | [[fly]] | [[hasten]] | [[hurry]] | [[run]] | [[rush]] | [[shoot]] | [[speed]] | [[tear]] | waltz | [[whisk]] | [[whiz]] | [[zoom]]
__Concepts__: [[ACTIONS - MOTION#move oneself quickly (150)\|move oneself quickly]]
__Antonyms__: decelerate, [[slow]]
"""###
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