Reputation: 325
How can I replace this string with another one regardless of whether the value is 2 or 4 or 5
<font size=\"2\"
I have it now :
replacingOccurrences(of: "font size=\"2\"", with: "font size=\"4\"")
But a 2 by default does not always arrive.
Upvotes: 1
Views: 59
Reputation: 72410
You can use replacingOccurrences(of:with:options:range:)
with .regularExpression
options.
let str = "<font size=\"3\""
print(str.replacingOccurrences(of: "(font size=\"[0-9]+\")", with: "font size=\"4\"", options: .regularExpression))
<font size="4"
Upvotes: 2