use .replace() for all trademark symbols on page
My genius IT Analyst decided at the last minute she wants ALL trademark symbols to be 2 sizes smaller than it's surrounding text. Since we don't have time to add tags to the entire template and CSS, we need a quick fix.
How can I replace ALL instances of the TM symbol with something like "<span style="font-size:1em;"&g开发者_C百科t;™</span>
"
Here's the regex for it. Pretty much what you have except you need to escape some characters.
\<span style="font-size:1em;"\>™\</span\>
Tested in UltraEdit
With sed it's quite easy to make these kind of changes automatically.
sed -e 's@®@<span style="font-size:1em;">®</span>@g' -i myfile.html
Firstly, if you're expecting font-size:1em;
to make your text smaller, you're going to get a surprise -- it will no affect the size at all; it'll resize it to exactly the size it would have been anyway. This is because sizes in ems are calculated relative to the parent element, and 1em
is always the same size as the parent (even if that parent is itself specified as 2em
or something like that).
What you probably want instead is 0.8em;
or something in that ball-park.
Anyway, I agree with @kobi's comment -- don't hard-code the font size into the HTML code; use a class and set a stylesheet on it. That way, when the designer changes their mind again, it'll be much much easier for you to do the same thing next time.
Others have already given you pretty much the exact regex you'll need, but please do adapt those answers to make it a class rather than setting the style directly.
精彩评论