import Foundation
let pattern = #"(?<=\bRate: )(?:[5-9]\d{3}|[1-9]\d{4,})\b"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
- Item: Oldman's_Romance
Rate: 50
- Item: Grasshopper's_Leg
Rate: 8000
- Item: Azure_Jewel
Rate: 9000
- Item: Grasshopper_Doll
Rate: 1500
- Item: Angel's_Arrival
Rate: 1000
- Item: Center_Potion
Rate: 700
- Item: Angel's_Departure
Rate: 10600
- Item: Left_Potion
Rate: 23471
- Item: Right_Potion
aRate: 6000
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"5000"#
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