import Foundation
let pattern = #"(extralibs_)(|avutil|avcodec|avformat|avdevice|avfilter|avresample|postproc|swscale|swresample)(?==)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
extralibs_avutil="-pthread -lva-drm -lva -lvdpau -lX11 -lm -L/usr/lib64/valgrind -ldrm -lm -lcoregrind-amd64-linux -lvex-amd64-linux -lgcc -lmfx -lstdc++ -ldl -lOpenCL -lva -ldl"
extralibs_avcodec="-lvpx -lm -lpthread -lvpx -lm -lpthread -lvpx -lm -lpthread -lvpx -lm -lpthread -lwebpmux -lm -lwebp -lm -pthread -pthread -lm -llzma -ldav1d -pthread -ldl -lsnappy -lstdc++ -lz -laom -lm -lpthread -lfdk-aac -lm -lgsm -lmp3lame -lm -lopenjp2 -lm -lopus -lm -lspeex -lm -ltheoraenc -ltheoradec -logg -lvorbis -lm -logg -lvorbisenc -lvorbis -lm -logg -lwebp -lm -pthread -lx264 -lpthread -lm -ldl -L/usr//usr/lib64 -lx265 -lstdc++ -lm -lgcc_s -lgcc -lgcc_s -lgcc -lrt -ldl -lnuma -lxvidcore -lva -ldl -lmfx -lstdc++ -ldl"
extralibs_avformat="-lm -lxml2 -lz -llzma -lm -lbz2 -lvapoursynth-script -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lvapoursynth -lzimg -ldl -lzimg -lstdc++ -lbluray -ldl -lpthread -lxml2 -lz -llzma -lm -lfontconfig -luuid -lexpat -lfreetype -lbz2 -lpng16 -lm -lz -lm -lz -lharfbuzz -lm -lglib-2.0 -pthread -lpcre -pthread -lgraphite2 -lbrotlidec -lbrotlicommon -lz -lssl -lcrypto -lz -ldl -pthread -lrtmp -lz -lgmp -lgnutls -pthread -lgmp -lunistring -latomic -ltasn1 -lidn2 -lp11-kit -lhogweed -lgmp -lnettle -lsrt -lstdc++ -lm -lgcov -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -lssl -lcrypto -lz -ldl -pthread"
extralibs_avdevice="-lm -L/usr/lib64/valgrind -ldrm -lm -lcoregrind-amd64-linux -lvex-amd64-linux -lgcc -lxcb -lXau -lXdmcp -lxcb-shm -lxcb -lXau -lXdmcp -lxcb-shape -lxcb -lXau -lXdmcp -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lXau -lXdmcp -lGL"
extralibs_avfilter="-pthread -lm -lfribidi -lass -lm -lfontconfig -luuid -lexpat -lfribidi -lfreetype -lbz2 -lpng16 -lm -lz -lm -lz -lharfbuzz -lm -lglib-2.0 -pthread -lpcre -pthread -lgraphite2 -lbrotlidec -lbrotlicommon -lnppig -lnppicc -lnppc -lnppidei -lva -lvidstab -lm -lgomp -lpthread -lzimg -lstdc++ -lOpenCL -lfontconfig -luuid -lexpat -lfreetype -lbz2 -lpng16 -lm -lz -lm -lz -lharfbuzz -lm -lglib-2.0 -pthread -lpcre -pthread -lgraphite2 -lbrotlidec -lbrotlicommon -lfreetype -lbz2 -lpng16 -lm -lz -lm -lz -lharfbuzz -lm -lglib-2.0 -pthread -lpcre -pthread -lgraphite2 -lbrotlidec -lbrotlicommon -ldl -lmfx -lstdc++ -ldl"
extralibs_avresample="-lm"
extralibs_postproc="-lm"
extralibs_swscale="-lm"
extralibs_swresample="-lm"
"""#
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