Skip to main content
Regex Match Dynamic Shortcode

Learn how to use the Regex Match Dynamic Shortcode to perform regular expression pattern matching on strings within your content.

Updated over a week ago

The Regex Match Dynamic Shortcode allows you to perform regular expression pattern matching on strings. This powerful tool enables you to check if a given string matches a specified regular expression pattern, returning a boolean result. It's particularly useful for complex string validation, search operations, or conditional content display based on pattern matching.

Syntax

{regex-match:pattern string}

The shortcode takes two required arguments:

1. pattern: The regular expression pattern to match against.

2. string: The string to be checked against the pattern.

Key arguments:

This shortcode does not use any key arguments.

Examples

Basic pattern matching:

{regex-match:"/[a-z]+/" "hello"}

This example checks if the string "hello" matches the pattern [a-z]+, which represents one or more lowercase letters. It will return true.

Checking for a specific format:

{regex-match:'/^\d{3}-\d{2}-\d{4}$/' "123-45-6789"}

This example validates if the string "123-45-6789" matches the pattern for a US Social Security Number format (XXX-XX-XXXX). It will return true.

Email validation:

{regex-match:'/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/' "user@example.com"}

This example checks if the string "user@example.com" matches a basic email format pattern. It will return true.

Using the result in an if statement:

{if:{regex-match:'/^[A-Z]{2}\d{4}$/' "AB1234"} [Display if match] [No match]}

This example uses the regex-match result within an if statement. It checks if the string "AB1234" matches a pattern of two uppercase letters followed by four digits. If it matches, "Display if match" will be shown; otherwise, "No match" will be displayed.

Special privileges

The Regex Match Dynamic Shortcode does not require any special privileges and can be used in any context where Dynamic Shortcodes are supported.

Did this answer your question?