LogoLogo
  • πŸ‘‹START HERE
    • Welcome!
  • ℹ️General
    • Release Notes
      • Full Feature Base Template
      • Services
      • Rule-based Automation
        • February 2025
        • January 2025
        • December 2024
        • November 2024
        • October 2024
        • September 2024
        • August 2024
        • July 2024
        • June 2024
        • May 2024
        • April 2024
        • March 2024
        • February 2024
        • January 2024
        • 2023
        • 2022
        • 2021
        • Dialog Design Update
    • Glossary of Terms
    • Authentication Methods
      • SSO (Single Sign-On)
      • Built-In User Management
    • Acceptable Use Policy
  • βš™οΈRule-based Automation
    • Overview
      • Account Settings
        • Profile
        • Team
        • Roles and Permissions
          • User Management
          • Project Permissions
      • Basic Concepts
        • Project Management
        • Version Management
        • Multi-Lingual Bots
          • Supported Languages
        • Managing User Interactions
          • Unexpected User Input
          • No User Input
    • Dialog Interface
      • Blocks
        • Conversation Logic
          • Start Conversation
          • Global
          • State
          • Intermediate Response
          • To Previous State
          • End Conversation
        • Subdialog
          • Reusable Subdialogs
        • Phone
          • Continue Listening
          • Call Control
        • Technical Logic
          • Service
          • Condition
          • Storage
        • Other
          • Note
      • Speech Assets
        • Intents
          • Utterances
          • Descriptions
        • Slots
          • Custom Slots
            • List Slots
            • Machine Learning Slots
            • Regex Slots
            • LLM Slots
          • Prebuilt Slots
            • DTMF Slot
        • Text Snippets
        • Dictionary
      • Variables
        • Intents
        • Slots
        • Storage
        • Text Snippets
        • Environments
        • Platform
        • Context
      • Services
        • Service Integration Guide
        • Service Development
        • Service Branches and Error Handling
        • Public Services
          • Date and Birthdate Recognition
          • Spelling Post-Processing for Phone
          • IBAN Validation
          • License Plate Validation
          • Address Search
          • Street Names per Postal Code
          • Email Service
          • SMS Service
          • API Adapter
          • Salesforce-Flow Connector
          • Opening Hours
          • Speech-to-Text Hints
          • Fuzzy Match Names
          • Delay Service
      • Debugger
        • Phone 2
        • WhatsApp
        • Textchat 2
    • Environments Interface
      • Service Keys
    • Deployments Interface
      • Creating a Release
      • Editing a Release
    • Text-to-Speech
      • Azure
      • ElevenLabs
      • OpenAI via Azure (Preview)
      • SSML
        • Audio
        • Break
        • Emphasis
        • Prosody
        • Say-as
        • Substitute
        • Paragraph and Sentence
        • Voice
    • Autocomplete
    • Parloa APIs
      • CallData Service and API
      • Conversation History API
      • Textchat V2 API
    • Phone Integrations
      • Genesys Cloud
        • Setting up the SIP Trunk
        • Sending/Receiving UUI Data
        • Creating a Script to Display UUI
      • SIP
      • Tenios
        • Setting Up an Inbound Connection
        • Setting Up an Outbound Connection
        • Transferring a Call
      • Twilio
      • Public IPs and Port Information
    • AI Integration Overview
      • Dual Intent Recognizer (DIR)
      • Dual Tone Multifrequency (DTMF) Intent
    • Analytics and Debugging
      • Understanding Conversations and Transactions
      • Managing Caller ID Data
      • Hangup Events and Triggered Analytics
      • Analytics Transactions: Data Structure and Insights
      • Dialog Analytics
      • Audit Logs
      • Parloa-hosted Analytics
    • Data Privacy
      • Anonymizing Personally Identifiable Information
    • NLU Training
      • NLU Training Best Practices
    • How To
      • Create a Scalable and Maintainable Bot Architecture
      • Implement OnError Loop Handling
      • Resolve the 'Service Unavailable' Error
    • Reference
      • Parloa Keyboard Shortcuts
      • Frequently Asked Questions (FAQ)
      • JavaScript Cheat Sheet
        • Using Regular Expressions (Regex)
  • 🧠Knowledge Skill
    • Introduction
    • Knowledge Collections
    • Knowledge Sources
    • Knowledge Skill Setup
      • Step 1 – Create a Knowledge Skill Agent
      • Step 2 – Configure a Knowledge Skill Agent
      • Step 3 – Configure a Knowledge Skill Agent
Powered by GitBook
On this page
  • Benefits of Using Regex
  • Implementing Regex in Parloa Bots
  • Step-by-Step Implementation
  • Example Code
  • Common Regex Patterns
  • Practical Examples

Was this helpful?

Export as PDF
  1. Rule-based Automation
  2. Reference
  3. JavaScript Cheat Sheet

Using Regular Expressions (Regex)

PreviousJavaScript Cheat SheetNextIntroduction

Last updated 11 months ago

Was this helpful?

Regex, or regular expressions, are powerful tools for pattern matching within strings. Despite their complex appearance, regex can be straightforward once understood and can significantly outperform ML models in terms of speed and accuracy for defined patterns.

Benefits of Using Regex

Implementing Regex in Parloa Bots

To use regex within a block in Parloa, follow these steps to extract the desired entities from input text.

Step-by-Step Implementation

Step 1 – Initialize a Variable

Create an empty container to hold any useful data found.

let match = "";
Step 2 – Retrieve Text to Check

Obtain the text from another storage variable or direct platform input.

let textCheck = storage.utterance;
Step 3 – Optional Text Cleaning

Simplify your regex by removing non-alphanumeric characters.

textCheck = textCheck.replaceAll(/[^\w\d]/g, '');
Step 4 – Define the Regex Pattern

Store the regex pattern in a variable for readability.

const flightNum_pattern = /([A-z]\s?){2}([\d]\s?){2,4}/;
Step 5 – Test for Pattern Match

Check if the text contains a pattern match.

if (flightNum_pattern.test(textCheck)) {
    match = flightNum_pattern.exec(textCheck)[0];
}
Step 6 – Return the Match

Ensure the match variable is the last one the block sees.

match;

Example Code

// Initialize a variable to hold the match
let match = "";

// Retrieve the text to be checked
let textCheck = storage.utterance;

// Optional: Remove non-alphanumeric characters for simplicity
textCheck = textCheck.replaceAll(/[^\w\d]/g, '');

// Define the regex pattern
const flightNum_pattern = /([A-z]\s?){2}([\d]\s?){2,4}/;

// Check if the text contains a pattern match
if (flightNum_pattern.test(textCheck)) {
    match = flightNum_pattern.exec(textCheck)[0];
}

// Return the match
match;

Common Regex Patterns

Here are some common regex patterns you might encounter:

  • Flight Numbers (IATA): [A-z]\s?\w\s?([\d]\s?){2,4}

  • Flight Numbers (ICAO): ([A-z]\s?){3}([\d]\s?){2,4}

  • German License Plates: ([A-zΓ„Γ–ΓœΓ€ΓΌΓΆ]\s?){1,3}([A-z]\s?){2}([\d]\s?){2,4}[EeHh]?

  • IBAN: ([A-z]\s?){2}([\d]\s?){20}

  • Insurance Numbers: ([\d]\s?){9}\w

Practical Examples

Example 1 – Flight Numbers

To handle flight numbers such as LH459, UA 59, TA1982, use the pattern:

  • Pattern: 2 letters + 2-4 digits

  • Example Regex: ([A-z]\s?){2}([\d]\s?){2,4}

Example 2 – Customer Numbers

For customer numbers starting with A, F, or H followed by a nine-digit number:

  • Pattern: [A|F|H][\d]{9}

Example 3 – Deconstructing Regex

Understanding project.json file patterns:

  • Pattern 1: \{\{.*?\}\}

  • Pattern 2: \{.*?\}

βš™οΈ

Accuracy

Regex provides high accuracy in pattern recognition for defined patterns.

Speed

Regex is faster to create and execute compared to training an ML model.

Efficiency

Regex simplifies many pattern-matching tasks once learned.

Storage