Try This. The below code will work when you are having multiple font sizes and you have set same font size for all.
func replaceFontSizes(withSize fontSize: Float, in replaceString: String?) -> String? {
var replaceString = replaceString
var r1 = (replaceString as NSString?)?.range(of: "font-size:")
while r1?.location != NSNotFound {
let strSub = (replaceString as NSString?)?.substring(from: r1?.location ?? 0)
var arrStr: [AnyHashable]?
if strSub?.contains("pt") ?? false {
arrStr = strSub?.components(separatedBy: "pt")
} else if strSub?.contains("px") ?? false {
arrStr = strSub?.components(separatedBy: "px")
}
let strReplace = arrStr?[0] as? String
replaceString = replaceString?.replacingOccurrences(of: strReplace ?? "", with: String(format: "font@@-@@size:%.2f", fontSize))
r1 = (replaceString as NSString?)?.range(of: "font-size:")
}
replaceString = replaceString?.replacingOccurrences(of: "font@@-@@size:", with: "font-size:")
return replaceString
}