Skip to content

RegExMatch Operator

Martin Danielsson edited this page Jul 23, 2015 · 2 revisions

Use the RegExMatch operator to validate an input string against an arbitrary regular expression.

What Type
Syntax RegExMatch(regEx, text)
regEx string
text any
Return type bool

The regEx is used to match the text against it. The regEx has to be correctly formatted as a regular expression; see the example below for an example (in terms of escaping etc.). If text matches against regEx, RegExMatch will return true, otherwise false.

Example: Use the following custom operator to simulate the way Salesforce validates email addresses:

<CustomOperators>
  <CustomOperator name="IsValidSfEmail" paramCount="1" returnType="bool">
    <Parameters>
      <Parameter name="email" type="string"/>
    </Parameters>
    <Function>RegexMatch("([a-zA-Z0-9_\-\.]+)@(((\[a-z]{1,3}\.[a-z]{1,3}\.[a-z]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3}))", %email)</Function>
  </CustomOperator>
</CustomOperators>

Use the custom operator as you would use the IsValidEmail Operator, e.g. in a filter definition:

<SourceFilters>
  <SourceFilter>FilterLog(IsValidSfEmail($email), "Invalid Email: " + $email)<SourceFilter>
</SourceFilters>

Or in a field definition:

<Fields>
  <Field name="EMail">$email</Field>
  <Field name="EMailValid">If(IsValidSfEmail($email), "yes", "no")</Field>
</Fields>

Example: Use the following custom operator to simulate the way Salesforce validates URIs:

<CustomOperators>
  <CustomOperator name="IsValidSfUri" paramCount="1" returnType="bool">
    <Parameters>
      <Parameter name="uri" type="string"/>
    </Parameters>
    <Function>RegexMatch("^(((http|https):\/\/){0,1}[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?){0,1}$", %uri)</Function>
  </CustomOperator>
</CustomOperators>

To be used just like the previous example.

See also:

Clone this wiki locally