import Foundation
let pattern = #"ENV GOSS_VERSION="(?<currentValue>.*)""#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ##"""
FROM kudobuilder/kuttl:v0.15.0
ENV GOSS_VERSION="v0.3.20"
ENV KUTTL_VERSION="v0.44.0"
# curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.26.0/bin/linux/amd64/kubectl && \
# chmod +x ./kubectl && \
# mv ./kubectl /usr/local/bin/kubectl && \
# Pending merge of https://github.com/goss-org/goss/pull/792 and https://github.com/kudobuilder/kuttl/pull/448
RUN echo "Installing carvel ytt version ${KUTTL_VERSION}" ; \
curl -L "https://github.com/goss-org/goss/releases/download/${KUTTL_VERSION}/ytt-linux-amd64" -o /usr/local/bin/ytt && \
chmod +rx /usr/local/bin/ytt && \
echo "Installing goss and kgoss version ${GOSS_VERSION}" ; \
curl -L "https://github.com/goss-org/goss/releases/download/${GOSS_VERSION}/goss-linux-amd64" -o /usr/local/bin/goss && \
chmod +rx /usr/local/bin/goss && \
curl -LO https://raw.githubusercontent.com/orange-cloudfoundry/goss/kgoss-kubectl-opts/extras/kgoss/kgoss -o /usr/local/bin/kgoss && \
chmod +rx /usr/local/bin/kgoss && \
/usr/local/bin/ytt --version && \
/usr/local/bin/goss -v && \
/usr/local/bin/kubectl version && \
/usr/local/bin/kgoss || echo "Installation done."
"""##
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