Jump to content

Change The Color of Certain words in a string


Recommended Posts

I have a string of text that will always have the word "call" and the word "click" in it. Those 2 words need to be a different color than the rest of the string. I can get the whole string to change to the color I need, just not those words, and leaving the rest of the string alone. I cant set up tags for it, because the rest of the string is different in every instance. I am new to this but have stumbled my way through writing rules to this point,.....I need some help with this one. Please, and thank you.
Link to comment
Share on other sites

If the entire string is pulled from a single field, you can create a text rule that replaces the desired words with the same words enclosed in tags, then check the "return tagged" box. A rule like the following would work:

return Field("YourField").replace(/(call)|(click)/gi,"<color name=\"Red\">$&</color>");


The / / notation indicates that regular expressions are being used.

Information inside () is the actual search being performed.

Information separated with | are an either/or search pattern.

The g trailing the 2nd / is saying to replace all instances of the search term (global).

The i trailing the 2nd / is saying to replace all instances regardless of case.

The $& inside the tags is pulling the found instance exactly as it appeared (in this case, case insensitive).

Link to comment
Share on other sites

Assuming you have the proper bold font loaded, you can just add the bold tags around the returned value (in red):

return Field("YourField").replace(/(call)|(click)/gi,"<color name=\"Red\">[color="Red"]<b>[/color]$&[color="red"]</b>[/color]</color>");

Alternatively, you could specify a specific font by name (as viewed in the FP text editor):

return Field("YourField").replace(/(call)|(click)/gi,"[color="red"]<f name=\"Arial Black\">[/color]<color name=\"Red\">$&</color>[color="red"]</f>[/color]");

Oh, and one overlooked FYI: the \ preceding the " in the tags is an escape character since the " would mean something different without the preceding backslash ;)

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...