NextGen Knowledge Center

Regular Expressions

These are used to search, match, or manipulate text strings based on patterns. In Mirth Connect regular expressions may be used for:

  • String replacement in the Mapper and Message Builder transformer steps
  • File-reader filename filter patterns
  • Error-condition matching in Alerts
  • String methods in JavaScript contexts.

Regular expressions have their own set of rules.

CharacterCharacter NameUsageExample
|Vertical bar/pipeSeparates alternativesthis|that – matches “this” or “that"
( )ParenthesesGroups characters together(A|a)bc – matches “Abc” or “abc”
^CaretMatches characters only at the start position^ab – matches “abc” but not "lab"
$Dollar signMatches characters only at the end positionAb$ - matches “lab” but not “abc”
?Question markIndicates 0 instances or 1 instance of the previous characterAb?cd – matches “acd” or “abcd”
*Asterisk/starIndicates 0 instances or multiple instances of the previous characterab*c – matches “ac,” “abc,” “abbc,” “abbbc,” etc.
+PlusIndicates 1 instance or multiple instances of the previous characterab+c – matches “abc,” “abbc,” “abbbc,” etc.
[ ]BracketsDenotes a set of characters that match

[abc] – matches “a,” “b,” or “c”

[^abc] – matches any characters except “a,” “b,” or “c”

[a-d] – matches “a,” b,” “c,” or “d”

When you use regular expressions in JavaScript, define them with the regular expression object or with this syntax: /pattern/attributes. Regular expression objects take two strings: pattern and attributes.

Attributes include “g” (global) and “i” (case insensitive): var exp = new RegExp("abc", "gi");

The test() method matches an expression to a given string: found = exp.test("I know my abc's");

JavaScript string object methods that use regular expressions include: match(), replace(), search(), split()

Example:

var myString = "Line1\nLine2\nLine3\n";
myString = myString.replace(/\n/g, "\r");