Using Regular Expressions in Rules

Last Updated -



Familiarity with using Regular Expression.

In business rules, it's sometimes necessary to match patterns rather than a static string. By selecting the "Use Regular Expression" option within the rules, Desk can evaluate items for patterns. A regular expression (RegEx or RegExp) is a special text string that defines a search pattern. You can think of regular expressions as wildcards on steroids. You're probably familiar with wildcard notations such as *.pdf to find all PDF files in a file manager. The regex equivalent is ^.*\.pdf$. 

Note: Features in this article requires the Standard plan or above. You can view our Pricing plans or reach out to Sales for more information.

Description Regular Expression Example
Date Format (mm/dd/yyyy) ^([\d]|1[0,1,2])/([0-9]|[0,1,2][0-9]|3[0,1])/\d{4}$ 06/14/2017
Decimal Number ^\d*[0-9](\.\d*[0-9])?$ 3.1415
Document Filenames ^[a-zA-Z0-9-_\.]+\.(pdf|txt|doc|csv)$ regular-expression-guide.pdf
Email Address ^(0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$
HTML Color Codes ^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$ #00ccff
Image Filenames ^[a-zA-Z0-9-_\.]+\.(jpg|gif|png)$ logo.png
IP Address ^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$
Multimedia Filenames ^[a-zA-Z0-9-_\.]+\.(swf|mov|wma|mpg|mp3|wav)$ company-presentation.swf
MySQL Date Format ^\d{4}-(0[0-9]|1[0,1,2])-([0,1,2][0-9]|3[0,1])$ 2017-06-14
Phone Number ^[2-9]\d{2}-\d{3}-\d{4}$ 877-226-9212
Time Format (hh:mm) ^([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1,2}$ 12:29
URL ^(http[s]?://|ftp://)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|||gov)$
Versatile Phone Number ^(([0-9]{1})*[-.(]*([0-9a-zA-Z]{3})*[-.)]*[0-9a-zA-Z]{3}[-.]*[0-9a-zA-Z]{4})+$ 1.877.226.9212



Below is a basic example of using Regular Expression within a Rule. It's only possible to use Regular Expression in Rule Conditions, it cannot be used in Rule Actions.

In this example, we want to automatically add the Label Billing to any Cases which have the word "Billing" in the Interaction Body. To do this, we would add an Inbound Interaction Rule with the below conditions.


To test regular expression you can use an online tool such as Rubular.

Related Articles