As String.replace supports regex what not use such an approach?
So, your stamp becomes:
$Text = $Text.replace("([C|c])arpal",'<font colour="blue">'+$1+'arpal</font>');
<font> tags went away in the last century (I remember first using them pre-CSS). A style ` would be more current HTML usage. Thus the above becomes:
$Text = $Text.replace("([C|c])arpal",'<span style="color: blue;">'+$1+'arpal</span>');
The latter works in preview, even in a TBX with no export template. Better, IMO would be to add an HTML template that defines, in the head, a
style block with CSS for different colours, etc., each as a CSS class. Now, with the blue text colour defined in CSS class ‘term_blue’, your stamp becomes:
$Text = $Text.replace("([C|c])arpal",'<span class="term_blue">'+$1+'arpal</span>');
- In the search term:
[C|c] matches an upper or lower-case character. The parentheses surrounding it set a back-references. This allows each match to preserve case.
- In the replace term:
- Because the HTML code needs to use double-quote, we use single quotes to define the replacement string.
- Using back-references, the terms (e.g.
$1) go outside the quoted parts of the replacement string otherwise they are treated as literal text (e.g. “$1”). thus the replacement string is composed of two quoted strings concatenated with a back-reference.