-
Notifications
You must be signed in to change notification settings - Fork 1
RegExCapture Operator
Use the RegExCapture
to capture a value from a string based on a regular expression.
What | Type |
---|---|
Syntax | RegExMatch(regEx, text) |
regEx |
string |
text |
any |
Return type | string |
RegExCapture
supports two different modes of capturing values via a regular expression: Matching the entire regular expression, or matching the first group of the regular expression.
If regEx
does not contain any regex groups, the entire capture (if the regular expression matches the text) will be returned. If the regular expression contains one or more groups, the first group's capture will be returned.
As a default (and currently not changeable), RegExCapture
works in the multiline mode. This means that the caret ^
not only matches the beginning of the text
string, but also the beginning of a line inside the text
, if text
contains line breaks. Likewise, $
not only matches the end of the string, but also the end of a line inside text
.
Example: The following text (an email) is passed as the field $MailBody
into the RegExCapture
operator:
From: somebody@somewhere.com
To: me@myself.com
Subject: This is a subject line!
Body:
Hello Me,
This is an email.
Bye!
The following table illustrates the difference between the usage of groups and not:
regEx |
returned string |
---|---|
^Subject: .*$ |
Subject: This is a subject line! |
^Subject: (.*)$ |
This is a subject line! |
In the first case, the regex does not contain any groups (introduced by parenthesises ( )
), alas, the entire matched expression ("capture") is returned. In the second line, a group is used to extract only the actual subject line.
If multiple groups are used, the first one is returned (this may be subject to change in the future by introducing further operators).
Remark: In order to speed up the processing of the regular expression, the regEx
parameter is assumed to be constant. Only in the first call, the regular expression will be compiled; the next times, it will just evaluate and match agains text
. In short: regEx
does not take dynamic content; or: just once.