import Foundation
let pattern = #"(?:[\S]+received_bytes_count )(?:true|false) ([\S]+)|(?:[\S]+received_bytes_count )([\S]+) (?:true|false)|(?:[\S]+received_bytes_count )([\S]+)"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
compute.googleapis.com/instance/network/received_bytes_count fleetwood false
compute.googleapis.com/instance/network/received_bytes_count false graceland
compute.googleapis.com/instance/network/received_bytes_count false creedence
compute.googleapis.com/instance/network/received_bytes_count false gke-oamstest-default-pool-bcb12758-nvb9
compute.googleapis.com/instance/network/received_bytes_count gke-oamstest-default-pool-bcb12758-nvb9 true
compute.googleapis.com/instance/network/received_bytes_count gke-oamstest-default-pool-bcb12758-6bzw false
compute.googleapis.com/instance/network/received_bytes_count true gke-oamstest-default-pool-bcb12758-6bzw
compute.googleapis.com/instance/network/received_bytes_count gke-oamstest-default-pool-bcb12758-s4td false
compute.googleapis.com/instance/network/received_bytes_count true gke-oamstest-default-pool-bcb12758-s4td
compute.googleapis.com/instance/network/received_bytes_count gke-oamstest-default-pool-bcb12758-nvb9
compute.googleapis.com/instance/network/received_bytes_count gke-oamstest-default-pool-bcb12758-6bzw
compute.googleapis.com/instance/network/received_bytes_count gke-oamstest-default-pool-bcb12758-s4td
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$1$2$3 Rcvd"#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
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