/regex Command

The /regex command allows you to work with regular expressions (regex) directly in Discord and Slack. Regular expressions are powerful pattern matching tools used for text manipulation, validation, and searching.

Available Subcommands

/regex test

Tests if a regex pattern matches a text string.

Usage

/regex test pattern: <regex pattern> text: <text to test>

Options

OptionDescriptionRequiredPlatform
patternThe regex pattern to testYesDiscord (parameter), Slack (flag with —pattern)
textThe text to test against the patternYesDiscord (parameter), Slack (flag with —text)

Example

/regex test pattern: ^[a-z]+$ text: hello

This will test if “hello” matches the pattern ”^[a-z]+$” (only lowercase letters).

/regex match

Finds all matches of a regex pattern in text.

Usage

/regex match pattern: <regex pattern> text: <text to search> [limit: <number>]

Options

OptionDescriptionRequiredPlatform
patternThe regex pattern to matchYesDiscord (parameter), Slack (flag with —pattern)
textThe text to find matches inYesDiscord (parameter), Slack (flag with —text)
limitMaximum number of matches to return (default: 10)NoDiscord (parameter), Slack (flag with —limit)

Example

/regex match pattern: \d+ text: There are 42 apples and 15 oranges

This will find all numbers in the text (“42” and “15”).

/regex replace

Replaces text matching a regex pattern.

Usage

/regex replace pattern: <regex pattern> text: <text to modify> replacement: <replacement text> [limit: <number>]

Options

OptionDescriptionRequiredPlatform
patternThe regex pattern to matchYesDiscord (parameter), Slack (flag with —pattern)
textThe text to perform replacements onYesDiscord (parameter), Slack (flag with —text)
replacementThe replacement text (can include 1,1, 2 for captured groups)YesDiscord (parameter), Slack (flag with —replacement)
limitMaximum number of replacements (0 for all, default: 0)NoDiscord (parameter), Slack (flag with —limit)

Example

/regex replace pattern: (\w+)@example\.com text: Contact john@example.com or sarah@example.com replacement: $1@company.com

This will replace all email addresses with @example.com domain to @company.com while preserving the username part.

/regex split

Splits text based on a regex pattern.

Usage

/regex split pattern: <regex pattern> text: <text to split> [limit: <number>]

Options

OptionDescriptionRequiredPlatform
patternThe regex pattern to split onYesDiscord (parameter), Slack (flag with —pattern)
textThe text to splitYesDiscord (parameter), Slack (flag with —text)
limitMaximum number of splits (0 for all, default: 0)NoDiscord (parameter), Slack (flag with —limit)

Example

/regex split pattern: [,;] text: apple,banana;orange,grape

This will split the text on commas and semicolons, resulting in [“apple”, “banana”, “orange”, “grape”].

/regex analyze

Analyzes a regex pattern and provides information about it.

Usage

/regex analyze pattern: <regex pattern>

Options

OptionDescriptionRequiredPlatform
patternThe regex pattern to analyzeYesDiscord (parameter), Slack (flag with —pattern)

Example

/regex analyze pattern: ^(\d{3})-(\d{2})-(\d{4})$

This will analyze the pattern for a social security number format (###-##-####) and provide information about the components of the regex.

Platform-Specific Implementation

Discord Implementation

  • Uses Discord’s named parameter system (e.g., pattern:, text:, replacement:)
  • Responses appear as embedded messages with color-coding
  • Analysis results are displayed in an organized, hierarchical format
  • Test results use color-coded indicators for matches/non-matches

Slack Implementation

  • Uses a flag-based approach for parameters (e.g., --pattern, --text, --replacement)
  • Arguments following flags that contain spaces should be enclosed in quotes
  • Responses are shown with formatted blocks displaying the result and related information
  • Test results use colored attachments to clearly indicate success or failure
  • Analysis results are split into manageable chunks if too large
  • Captured groups in matches are clearly labeled and formatted

Common Regex Patterns

Here are some commonly used regex patterns:

PatternDescriptionExample
\d+One or more digits”123”, “42”
\w+One or more word characters (letters, digits, underscore)“hello_123”
[a-zA-Z]+One or more letters”HelloWorld”
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Email validationuser@example.com
^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$Password with at least 8 characters, one letter and one number”password123”
^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$URL validationhttps://example.com

Using Captured Groups

Regular expressions can capture parts of the matched text using parentheses (). These captured groups can be referenced in replacements using $1, $2, etc.

For example:

/regex replace pattern: (\w+):(\d+) text: score:42 lives:3 replacement: $1 = $2

This will convert “score:42 lives:3” to “score = 42 lives = 3”.

Notes

  • Complex regular expressions may have performance implications
  • The regex engine uses Go’s standard library implementation
  • Invalid regex patterns will return appropriate error messages
  • Very long inputs or results may be truncated in the output