knots.io

Mastering regex in Zendesk: A beginner’s guide

Illustration of a customer support workflow using regular expressions (regex) to automate ticket processing in Zendesk
Graphic

Imagine you’re a customer service manager overseeing a team that handles a high volume of customer inquiries via email and phone. Every day, your team processes hundreds of messages, many containing sensitive details like order numbers, account information, and contact details. Manually sorting and extracting these details is time-consuming and error-prone. To efficiently manage these messages and provide prompt assistance, you need a way to extract relevant data quickly.

Enter regular expressions (regexes). By defining specific patterns, you can parse text and automatically isolate order numbers, email addresses, phone numbers, and other crucial details. With these tools, your team can streamline workflows, reduce manual input, improve response times, and ensure sensitive information is handled appropriately.

This guide introduces regular expressions for Zendesk, covering the fundamentals, key syntax, common patterns, and practical applications.

Where do you use a regex in Zendesk?

Zendesk uses regexes in several areas to help automate workflows and manage customer interactions efficiently. Here are the primary places where regex comes into play:

  • Custom ticket fields: Regex allows for validation of structured inputs like email addresses, phone numbers, and order numbers.
  • Placeholders: Use a regex to define placeholders, which come into play when using Macros.
  • Reports & Analytics – In Zendesk Explore, regex can help filter and categorize data more precisely. For example, it can be used to track tickets from specific email domains or group responses based on keywords. Learn more.
  • Advanced AI Agents – Zendesk’s AI bots use regex to detect patterns in messages, helping with ticket categorization and automated responses. This improves accuracy and efficiency in handling customer inquiries. More details here.
  • Third-party apps: Apps like Knots’ Ticket Parser use regexes to extract and categorize text from support tickets.

By using regex in these areas, support teams can reduce manual effort, increase accuracy, and enhance customer interactions.

What are regular expressions (regexes)?

Regular expressions are a way to find patterns in text. Instead of manually searching for specific words, numbers, or phrases, regex lets you define rules to find and process matching patterns automatically.

Think of a regex as a smart search tool that allows you to:

  • Find specific words or numbers in emails, messages, or documents.
  • Check if a text matches a format, like an email or phone number.
  • Automatically extract important details from customer messages in Zendesk.

Why use regular expressions?

    With its flexibility in text processing, a regex helps to automate and speed up your workflow. Many programming languages and tools support it, making it a valuable skill for handling text-based data like customer information, log files, or structured documents. It’s especially widely used in customer service tools like Zendesk to categorize and process incoming tickets efficiently.

    Common use cases include:

    • Checking  input formats: Making sure customers enter correct email addresses or phone numbers.
    • Searching and replacing text: Finding specific patterns in text to replace them, useful for code refactoring or text editing.
    • Extracting key details: Automatically pulling order numbers or product IDs from messages or other  large datasets, logs, or documents.
    • Parsing text: Breaking down and extracting structured components from complex text data  for analysis or processing.
    Zendesk ticket field setup with regex validation for structured inputs like email addresses and order numbers

    Understanding regex syntax

        Regex patterns may seem complicated at first, but they are just rules for finding text. To master them, it’s important to understand the fundamental building blocks. Let’s break down the key components of regular expressions.

        Characters and metacharacters

        A regex combines literal characters, which match exactly, with special metacharacters that have unique meanings.

        • Literal characters are regular letters that match themselves exactly. For example, searching for cat will find the word “cat” in the text.
        • Metacharacters (or Special characters) are special symbols with unique meanings. These symbols help make searching for words more flexible and precise.
          • . (dot): This symbol can stand for any single character. For example, if you use c.t, it will match words like “cat”, “cut”, and “cot” because they fit the pattern.
          • * (asterisk): This symbol means “zero or more” of the character before it. So, ca*t can match “ct” (with no ‘a’), “cat”, or “caat” (with two ‘a’s).
          • + (plus): This symbol means “one or more” of the character before it. For instance, ca+t will match “cat” and “caat” but not “ct” because the ‘a’ is needed at least once.
          • ? (question mark): This symbol makes the character before it optional. For example, colou?r will match both “color” and “colour” because the ‘u’ can either be there or not.
          • [] (brackets): These define a set of characters you want to match. For example, [abc] will match any one of the characters “a”, “b”, or “c”.
          • ^ (caret): This symbol tells us to look for something at the very start of the string. For instance, ^Hello will find strings that start with “Hello”.
          • $ (dollar sign): This symbol indicates we are looking for something at the very end of the string. For example, world$ will match strings that end with “world”.

        Character classes and quantifiers

        When working with text, it’s useful to identify groups of characters instead of specific ones. Focusing on character categories and using quantifiers can help clarify how often these groups appear in the text. 

        • Common character classes:
          • The symbol \d matches any digit from 0 to 9. This is useful when you’re searching for numbers, like order IDs.
          • The symbol \w matches any letter, number, or underscore. This helps when you want to find usernames or similar text.
          • The symbol \s matches any space, like the spaces you use when typing. This is great for identifying empty spots in text.
        • Quantifiers:
          • Exact matches: The notation {n} looks for exactly ‘n’ occurrences of a character. For example, a{3} finds “aaa” but not “aa”.
          • At least matches: The notation {n,} finds ‘n’ or more occurrences. So, a{2,} would find “aa”, “aaa”, or “aaaa”.
          • Range of matches: The notation {n,m} searches for between ‘n’ and ‘m’ occurrences. For instance, a{2,4} will match “aa”, “aaa”, or “aaaa”.

        Practical examples: Regex for Zendesk in action

        Let’s explore how to apply regexes beyond the theory and into real-world scenarios. Below are some practical examples that you can use right away.

        Validating an email address

        Ever needed to ensure users input valid email addresses? Use this regex:

        ^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$

        ✅ Matches: user@example.com, hello.world@test.net 

        ❌ Does not match: user@.com, @example.com

        Matching phone numbers

        Phone numbers come in various formats. This regex captures different variations:

        \d{3}[-.]?\d{3}[-.]?\d{4}

        ✅ Matches: 123-456-7890, 123.456.7890, 1234567890 

        ❌ Does not match: 123-45-678

        Extracting URLs from text

        Need to pull out URLs from a document or message? Use this:

        https?://[^\s/$.?#].[^\s]*

        ✅ Matches: http://example.com, https://www.test.net/path 

        ❌ Does not match: www.example.com (without http or https)

        Regex in Zendesk: Best practices

        To make regexes more effective and easier to manage in Zendesk:

        • Keep it simple: Use straightforward patterns to avoid complexity.
        • Test your patterns: Tools like regex101 help ensure accuracy before implementation. Start building your patterns bit by bit, testing each section as you go.
        • Think about variations: Different formats (like dates or phone numbers) require flexible patterns.
        • Escape special characters: Use \. instead of . when searching for actual dots.

        To take automation further, Knots apps help teams automate ticket processing, data extraction, and workflow optimization in Zendesk. The Ticket Parser app simplifies structured data extraction from support tickets, reducing manual work and improving efficiency.

        Conclusion: Why regexes matter for Zendesk

        Regexes help automate ticket processing, data extraction, and input validation – making support teams more efficient. If you’re just starting, focus on simple patterns and use tools like Knots Ticket Parser to make the most of regex without needing deep technical knowledge.

        Email
        Print