Alejandro
Alejandro

Reputation: 325

Replace string regardless of the value

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

Answers (1)

Nirav D
Nirav D

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

Related Questions