Caplin Trader 5.1.0

Class: module:ct-element/formatter/RegExpFormatter

module:ct-element/formatter/RegExpFormatter()

new module:ct-element/formatter/RegExpFormatter()

Transforms a string using a standard JavaScript regular expression.

RegExpFormatter is typically used in the XML Renderer Framework, but can be invoked programmatically as in the following examples which evaluate to "8987551787.0" and "Buy USD" respectively:

RegExpFormatter.format("8987551787.0", { match:"[A-Z]" })
RegExpFormatter.format("Buy.USD", { match:"(\\.", replace:" " })
Implements:

Methods

format(vValue, mAttributes) → {String}

Transforms a string using a standard JavaScript regular expression.

By default, only the first match is substituted with the replacement string (unless the "g" option is supplied) and the match is case sensitive (unless the "i" option is supplied).

Parameters:
Name Type Description
vValue Variant

the string.

mAttributes Map

the map of attributes.

Properties
Name Type Attributes Default Description
match String

The string to match (a standard js RegExp).

replace String <optional>
''

The string to use as replacement.

flags String <optional>

The regular expression flags to be applied (standard js RegExp flags).

Implements:
Returns:

the string, converted by the regular expression.

Type
String