import Foundation
let pattern = #"(?<=m=video)(?s)(.*)(a=sendrecv)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
v=0
o=- 582127838 582127838 IN IP4 172.17.217.8
s=Commend
c=IN IP4 172.17.217.8
t=0 0
m=audio 16882 RTP/AVP 8 107 9 0
a=rtpmap:8 PCMA/8000
a=rtpmap:107 opus/48000/2
a=fmtp:107 useinbandfec=1
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=ptime:20
a=maxptime:20
a=sendrecv
m=video 15132 RTP/AVP 99
a=rtpmap:99 H264/90000
a=sendrecv
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$1a=sendonly"#
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