Regex Commands
The /regex
command is a tool for working with regular expressions directly in Discord. It’s perfect for:
- Quick-testing regex patterns while you’re building them
- Creating a library of commonly used patterns for your project or server
- Sharing and reusing regex patterns with your team or community
- Visualizing regex matches to ensure they work as intended
Whether you’re validating input formats, building search patterns, or creating text filters, the regex command helps you build and test patterns collaboratively with your team or community to facilitate knowledge sharing.
Basic Usage
Test Pattern
/regex test [pattern] [text] [action]
Test a regex pattern with different visualization options.
Parameters:
pattern
- The regular expression pattern to testtext
- The text to test againstaction
- How to visualize the matches:Match
- Show a list of all matches with their positionsHighlight
- Highlight all matches in the textSplit
- Split text using the pattern as delimiter
Examples:
# Show matches
/regex test pattern:"\\d+" text:"abc123def456" action:match
# Result: Shows matches: "123", "456"
# Highlight matches
/regex test pattern:"\\w+@\\w+\\.\\w+" text:"Contact us at support@example.com" action:highlight
# Result: Highlights email address in the text
# Split text
/regex test pattern:"\\s*,\\s*" text:"apple, banana, orange, pear" action:split
# Result: Shows parts: ["apple", "banana", "orange", "pear"]
Pattern Library
Add Pattern
/regex add [name] [pattern] [description]
Save a regex pattern to your server’s library for future use. If enabled in CodeCord Dashboard, adding a regex pattern to the server library requires approval from a moderator.
Parameters:
name
- A name for the patternpattern
- The regex patterndescription
(optional) - Description of what the pattern matches
Get Pattern
/regex get [name|id]
Retrieve a pattern from the library.
Parameters:
name
- Name of the pattern to findid
- ID of the specific pattern
List Patterns
/regex list [page] [unapproved]
List all patterns in your server’s library.
Parameters:
page
(optional) - Page number for paginationunapproved
(optional) - Show only patterns awaiting approval
Remove Pattern
/regex remove [id]
Remove a pattern from the library.
Parameters:
id
- ID of the pattern to remove
Common Examples
Testing Email Pattern
/regex test pattern:"\\b\\w+@\\w+\\.\\w+\\b" text:"Contact us at support@example.com or sales@example.com" action:highlight
# Highlights email addresses in the text
Testing Phone Numbers
/regex test pattern:"\\d{3}-\\d{3}-\\d{4}" text:"Call us at 555-123-4567" action:match
# Shows if phone number format matches
Splitting CSV Data
/regex test pattern:"\\s*,\\s*" text:"apple, banana, orange, pear" action:split
# Splits CSV data into clean parts
Saving Common Patterns
/regex add name:"email" pattern:"\\b\\w+@\\w+\\.\\w+\\b" description:"Matches email addresses"
# Saves the email pattern to your library
Notes
- Patterns are saved per server
- Library provides easy access to commonly used patterns
- Test your patterns before saving them to ensure they work as expected
- Use descriptive names and descriptions when saving patterns
- The test command provides three different ways to visualize matches
- Highlighting is great for verifying pattern matches in context
- Split action is useful for text processing and data extraction