Regular Expressions (Regex) Guide
Regular Expressions (regex or regexp) are patterns used to search, match, or validate text. In the world of Webex Contact Center, Webex Connect, and Webex AI Agents, regex often plays a key role behind the scenes — whether you're filtering reports, validating phone numbers, or routing conversations based on input patterns.
Where Regex Shows Up in Webex:
Analyzer Report Filters: Match patterns in team names, agent IDs, ANI/DNIS, or queue names (e.g., .*Sales.*).
Dial Plan Rules: Validate phone numbers using pattern matching (e.g., 1[0-9]{3}[2-9][0-9]{6}).
Webex Connect Branch Conditions: Route messages based on keyword matching inside incoming data (e.g., .*urgent.*).
AI Agent Studio (Entities & Validation): Recognize user inputs like phone numbers or dates using regex-based entities.
- Improve flexibility in your reports, bots, and flows.
- Handle tricky scenarios like casing mismatches ("WhatsApp" vs. "whatsapp").
- Validate data formats cleanly without complex scripts.
- Troubleshoot matching issues faster with better understanding of the patterns.
This cheatsheet is a practical, easy-to-follow guide focused on the kind of regex patterns you'll actually use when working with Webex tools. It's not about mastering regex theory — it's about getting your jobs done effectively.
Regex Basics: Symbols, Quantifiers & Character Classes
Regular Expressions (regex) use special symbols and syntax to define search patterns. Here are the core building blocks that you'll use to write most of your regex patterns.
Core Regex Symbols
| Symbol | Meaning | Example | Matches |
|---|---|---|---|
| . | Any single character (except newline) | c.t | cat, cut, cot |
| * | Zero or more repetitions | lo* | l, lo, loo, looo... |
| + | One or more repetitions | lo+ | lo, loo, looo... |
| ? | Zero or one occurrence (optional) | colou?r | color, colour |
| ^ | Start of string | ^Hello | Matches "Hello World" but not "Say Hello" |
| $ | End of string | World$ | Matches "Hello World" but not "World Cup" |
| \d | Any digit (0-9) | \d\d\d | 123, 456, etc. |
| \w | Word character (letters, digits, underscore) | \w+ | abc, user_1, hello123 |
| \s | Whitespace (space, tab, newline) | \s+ | spaces, tabs, line breaks |
| [abc] | Any one of a, b, or c | [ch]at | cat, hat |
| (abc|def) | Either abc or def | (cat|dog) | cat, dog |
Quantifiers
-
{n} — Exactly n occurrences.
Example: \d{4} → 4 digits like 1234. -
{n,} — n or more occurrences.
Example: \d{3,} → 3 or more digits. -
{n,m} — Between n and m occurrences.
Example: \d{2,4} → 2, 3, or 4 digits.
Character Classes (Predefined & Custom)
- [abc] — Matches any one character: a, b, or c.
- [^abc] — Matches any character except a, b, or c.
- [a-z] — Matches any lowercase letter.
- [A-Z] — Matches any uppercase letter.
- [0-9] — Matches any single digit.
- \d — Shortcut for [0-9].
- \w — Matches letters, numbers, or underscore ([a-zA-Z0-9_]).
- \s — Matches any whitespace (space, tab, newline).
Common Regex Patterns Reference
Here are some ready-to-use regex patterns for everyday use in reporting, dial plans, message routing, and entity recognition.
Email Validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Matches standard email addresses like [email protected].
Phone Number (US Format)
^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$
Matches US phone numbers with or without separators: 123-456-7890, (123) 456 7890, etc.
URL Validation
^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?$
Matches most HTTP/HTTPS URLs like https://example.com/path.
Match Any String (Catch-All)
- .* — Matches zero or more characters (even an empty string).
- .+ — Matches one or more characters (non-empty).
Case-Insensitive Matching Workaround
There may be scenarios where the solution does not support /i regex flag for case-insensitive matching. To match both uppercase and lowercase, use character classes:
.*[Ww][Hh][Aa][Tt][Ss][Aa][Pp][Pp].*
Matches whatsapp, WhatsApp, WHATSAPP, etc.
Quick Reference of Helpful Patterns
- Starts with: ^pattern
- Ends with: pattern$
- Contains (anywhere): .*pattern.*
- OR condition: (pattern1|pattern2)
- Optional group: colou?r (matches color and colour)
Real-World Regex Use Cases in Webex
Regex is baked into many parts of the Webex Contact Center, Connect, and AI Agent workflows. Here's a breakdown of where it comes into play and why using the right pattern makes your configuration smarter and more flexible.
| Where It's Used | Example Pattern | Why Use Regex Here |
|---|---|---|
| Analyzer Report Filters | .*Sales.* | Match queue names, team names, or agent IDs containing the word "Sales" anywhere in the string. |
| Dial Plan Rules | 1[0-9]{3}[2-9][0-9]{6} | Validate outbound phone numbers against specific dialing formats before sending calls to PSTN. |
| Webex Connect Branch Conditions | .*(urgent|important).*? | Route incoming messages based on keywords (e.g., "urgent" or "important") found in the content of messages. |
| AI Agent Studio: Entity Recognition | ^\d{4}$ | Validate user input like a 4-digit PIN or year inside your bot interactions. |
| Data Field Cleanup / Pattern Matching | ^[A-Z]{3}\d{4}$ | Ensure data like product codes (e.g., "ABC1234") follow the expected format before processing. |
These patterns help you filter, validate, and route data directly inside the Webex platforms without needing custom code. Whether it's filtering a report, validating user inputs, or deciding where a message should go, regex lets you define logic that adapts to your needs.
Common Mistakes & Gotchas (and How to Avoid Them)
Regex can be powerful, but it also comes with a few tricky areas where things often go wrong. Here are some of the most common mistakes to watch out for when using regex inside Webex platforms.
Case Sensitivity Confusion (Especially in Analyzer)
Regex matching is case-sensitive by default. For example, .*whatsapp.* will match "whatsapp" but not "WhatsApp" or "WHATSAPP".
Solution: Use character classes to manually handle case:
.*[Ww][Hh][Aa][Tt][Ss][Aa][Pp][Pp].*
Greedy Matching When You Don't Want It
The * and + quantifiers are "greedy" by default — they match as much as possible.
Problem Example: <.*> on <div>Hello</div> matches the entire string, not just the opening tag.
Solution: Use the "lazy" version by adding ?:
<.*?>
Forgetting to Escape Special Characters
Characters like ., +, *, ?, (, ), [, ], {, }, ^, $, \, and | have special meanings in regex.
Solution: Use a backslash \ to escape them when you mean the literal character.
Example:
To match example.com, use:
example\.com
Anchors Misunderstood
^ matches the start of a string, $ matches the end. Sometimes people expect them to match the start/end of each line (which they don't by default unless multiline mode is supported).
Example:
^Hello$ matches only if the entire string is exactly "Hello".
Overcomplicating the Pattern
Trying to capture too many conditions in a single pattern can make regex unreadable and hard to maintain.
Solution: Break down logic into smaller, testable patterns. Use OR groups like (pattern1|pattern2) only where necessary.
Best Practices & Debugging Tips
Writing good regex is not about being clever — it's about being clear, maintainable, and reliable. These best practices will help you avoid common issues and make your patterns easier to work with.
Best Practices
- Start simple and add complexity only as needed. Avoid trying to solve everything with one pattern.
- Use anchors (^ and $) when you want to control where the match happens (start, end, or whole string).
- Group clearly using parentheses () and use non-capturing groups (?:...) when you don't need the match result.
- Always escape special characters when matching them literally (e.g., use \. to match a period).
- Comment your patterns (if your environment allows) or document them outside your regex to explain intent.
- Test with a variety of input cases — including expected matches, expected non-matches, edge cases, and null or empty inputs.
Debugging Tips
- Break complex patterns into smaller parts and test each segment individually.
- Use online testing tools to visualize matches and groups (listed below).
- Double-check greedy vs. lazy behavior when using * or +.
- Log input values (where possible) to confirm what data is actually being evaluated against the pattern.
- Use test data that includes problematic inputs like extra spaces, mixed case, special characters, or unexpected formats.
Recommended Regex Testing Tools
- regex101.com — Interactive tester with explanations for each part of your pattern.
- regexr.com — Real-time regex playground with a handy reference guide.
- debuggex.com — Visual diagramming of regex patterns and matches.
Closing Thoughts & References
This cheatsheet is meant to be a quick, practical guide for using regex effectively within Webex Contact Center, Webex Connect, and Webex AI Agent Studio. It focuses on the kinds of patterns you're most likely to use — not every obscure feature of regex.
Remember, regex is best used where it simplifies your logic — but it's just one tool in your toolkit. Whenever possible, test your patterns thoroughly before deploying them in production flows.
If you're interested in digging deeper into regex beyond this cheatsheet, here are some trusted resources to explore:
Official References and Learning Resources
- MDN Web Docs: Regular Expressions Guide — Great for fundamentals and examples.
- regex101.com — Interactive regex tester with explanations and match breakdown.
- regexr.com — Real-time regex testing playground with reference material built-in.
- debuggex.com — Visual diagramming of regex patterns, helpful for complex expressions.
Happy pattern matching — and may your matches always be intentional!