Script Examples: Individually Format Characters within a Field

The following are some examples of configuring character-level formatting by using a Script data source. Character-level formatting methods are not supported in business rules.

Important! Patterns for character-level formatting and for values returned from data map entries are governed by the Java syntax for regular expressions.

Escape sequences are required for the following characters. Precede the character with a double backslash.
< > ( ) [ ] { } | ^ - = + * $ ! ? . \

By default, literal text within a pattern is case sensitive. You can make a pattern case insensitive by beginning it with the special construct (?i). If you configure both patterns and ranges in a Character-Level format source, ranges are resolved before patterns.

For more information about Java syntax for regular expressions, see "Scripting, Java, and XML" in External Links.

Example 1: Make all instances of an allergen name bold (case sensitivity)

You want all instances of the allergen name Peanuts within a text field to be bold, regardless of case. You can accomplish this by using the following script in a Script data source:

var field1=getField("/Body/Text0001");

field1.addEffect("BOLD","(?i)(peanuts)");

Example 2: Apply special formatting to the first character (matching by range)

You want to format the first character in a field as bold, 16-point Letter Gothic text. You can accomplish this by using the following script in a Script data source:

var field1=getField("/Body/Text0001");

var myStyleMap=field1.getStyleMap();

myStyleMap.put("FONT","Letter Gothic");

myStyleMap.put("SIZE","16");

myStyleMap.put("BOLD","");

field1.addStyleMulti(myStyleMap,0,0);

Tip: You can use a Character-Level format source to configure character-level formatting instead. For more information, see Configuring Format Sources.