I would like to change the font-size in an HTML string that I have to be half of its size.
E.g.
<div style="font-family:'Arial';font-size:43px;color:#ffffff;">
Will be
<div style="font-family:'Arial';font-size:21.5px;color:#ffffff;">
and
<div style="font-size:12px;">
Will be
<div style="font-size:6px;">
How can I do it with NSRegularExpression?
Please note that 12 and 6 and 43 and 21.5 are only examples. I need regex since it has to be a general solution for different font-size
I am a bit reluctant to give an answer using regular expressions, because it has been stated repeatedly that parsing HTML with regex is considered harmful, impossible, dangerous to your mind, etc. And all that is correct, it is not my intention to claim anything different.
But even after all that warnings, OP has explicitly asked for a regex solution, so I am going to share this code. It can at least be useful as an example how to modify a string by looping over all matches of a regular expression.
Output: