import Foundation
let pattern = #"(.*?)((\@Comment\{Annotation: key:START;\})|$)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .dotMatchesLineSeparators)
let testString = #"""
@Comment{Annotation: key:START;}
@Comment{OriginalFile: path:F:\Dropbox\Literature\FileSeperations\RC_ARS_NewUniquesAlphaSep;}
@Comment{OriginalFile: name:ASF_UniqueToCheck.bib;}
% Encoding: UTF-16
@Comment{jabref-meta: databaseType:bibtex;}
@Comment{Annotation: key:START;}
@Comment{OriginalFile: path:F:\Dropbox\Literature\FileSeperations\RC_ARS_NewUniquesAlphaSep;}
@Comment{OriginalFile: name:Author_A.bib;}
% Encoding: UTF-16
@Article{Asbrink2000,
author = {\AA sbrink, Sara and Zickert, Agneta and Bratt, Johan and Gyllenhammar, Hans and Palmblad, Jan},
title = {{No effect of carvedilol on nitric oxide generation in phagocytes but modulation of production of superoxide ions.}},
journal = {Biochemical pharmacology},
year = {2000},
volume = {59},
number = {8},
pages = {1007--13},
month = apr,
abstract = {Since carvedilol has been claimed to possess antioxidative effects, this drug might affect functional responses, including nitric oxide (NO) generation, of polymorphonuclear neutrophils (PMN) and macrophages. When we assessed the effects of carvedilol on PMN responses in vitro, we observed that carvedilol dose dependently modulated generation of superoxide ions by NADPH oxidase when induced by the formylpeptide formyl-methionyl-leucyl-phenylalanine (fMLP) or the phorbol ester phorbol myristate acetate. This effect was not coupled to diminished phospholipase C activity. In contrast to the effect on NADPH oxidase, neither the fMLP-elicited NO generation by PMN nor the response of the murine macrophage cell line J774 to lipopolysaccharide was affected. There was no evidence from cell-free assay systems that carvedilol is a scavenger for superoxide ions or NO. Moreover, carvedilol did not affect other reactions dependent on NO, e.g. spontaneous or fMLP-stimulated PMN migration or lipoxin A(4)-, fMLP-, or A23187-induced neutrophil cytotoxicity for human umbilical vein endothelial cells. Thus, these effects point to the possibility that carvedilol modulates the NADPH oxidase of PMN but leaves the nitric oxide synthase of phagocytes intact.},
issn = {0006-2952},
keywords = {1- and,1-receptors and non selectively,2-adrenoreceptors,Animals,Antihypertensive Agents,Antihypertensive Agents: pharmacology,Calcium,Calcium: metabolism,Carbazoles,Carbazoles: pharmacology,Cytochrome c Group,Cytochrome c Group: metabolism,Free Radical Scavengers,Free Radical Scavengers: pharmacology,GTP-Binding Proteins,GTP-Binding Proteins: metabolism,Humans,Leukocyte,Leukocyte: drug effects,Mice,Neutrophils: drug effects,Neutrophils: metabolism,Nitric Oxide: metabolism,Oxidation-Reduction,Phagocytes,Phagocytes: drug effects,Phagocytes: metabolism,Propanolamines,Propanolamines: pharmacology,Superoxides,Superoxides: metabolism,Type C Phospholipases,Type C Phospholipases: metabolism,antag-,antihypertensive drug that,carvedilol,carvedilol is a vasodilating,chemotaxis,endothelial cells,moreover,neutrophils,nitric oxide,onizes,selectively blocks,superoxide ions},
owner = {ASF_A},
pmid = {10692566},
timestamp = {2016.06.25},
url = {http://www.ncbi.nlm.nih.gov/pubmed/10692566},
}
"""#
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