Loading...
These are used to search, match, or manipulate text strings based on patterns. In Mirth Connect regular expressions may be used for:
Regular expressions have their own set of rules.
Character | Character Name | Usage | Example |
---|---|---|---|
| | Vertical bar/pipe | Separates alternatives | this|that – matches “this” or “that" |
( ) | Parentheses | Groups characters together | (A|a)bc – matches “Abc” or “abc” |
^ | Caret | Matches characters only at the start position | ^ab – matches “abc” but not "lab" |
$ | Dollar sign | Matches characters only at the end position | Ab$ - matches “lab” but not “abc” |
? | Question mark | Indicates 0 instances or 1 instance of the previous character | Ab?cd – matches “acd” or “abcd” |
* | Asterisk/star | Indicates 0 instances or multiple instances of the previous character | ab*c – matches “ac,” “abc,” “abbc,” “abbbc,” etc. |
+ | Plus | Indicates 1 instance or multiple instances of the previous character | ab+c – matches “abc,” “abbc,” “abbbc,” etc. |
[ ] | Brackets | Denotes 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");