Skip to main content

How to use regex101

Overview

KurocoEdge allows the use of regular expressions, but some regex patterns (lookaheads, lookbehinds, etc.) are not supported. You can use regex101 to check if your regex pattern is syntactically correct.
regex101 is an online tool for testing and debugging regular expression patterns. Follow the steps below to learn how to use regex101.

1. Access the regex101 website

First, access the regex101 website using any web browser. You can click the following URL to access it.

regex101 website

2. Select Rust

Select Rust from the sidebar menu. Image from Gyazo

3. Enter the regex pattern

Once you have accessed the regex101 website, enter your regex pattern in the "Regular Expression" field. A regex pattern is a special string that defines the rules for search and replace operations.

For example, the following regex pattern is used to match directory with the /news- prefix:

^/news-.*

Image from Gyazo

4. Enter the test string

Next, enter the text you want to apply the regex pattern to in the "Test String" field. The test string is the text to which the regex pattern will be applied.

For example, consider the following text to which you want to apply the regex pattern:

/news-20230101

Image from Gyazo

5. Perform the test

Once the regex pattern and the test string are entered, the "Match Information" section will display the match information. This section shows information about the substrings that match the regex pattern, including their positions.

Additionally, the matched parts in the text will be highlighted for visual representation. Image from Gyazo

6. Set flags and options (optional)

In regex101, you can also set flags and options for your regex pattern. Flags and options modify the behavior of the regular expression matching.

Flags and options are specified after the regex pattern, separated by slashes (/). Here are some common flags and options:

  • i flag: Perform case-insensitive matching.
  • g flag: Perform a global search for all matches within the text.
  • m flag: Perform multiline matching. Changes the interpretation of line boundaries (^ and $).
  • s flag: Allow the dot (.) to match newline characters as well.
  • x flag: Ignore whitespace characters within the regex pattern and enable comments.

Flags and options can be added to the regex pattern.
For example, using (?i)a(?-i)b will perform a case-insensitive matching on a.
a matches either both lowercase a or uppercase A, but the b only matches lowercase b.
If the closing tag (?-i) is not used, then the entire string following the starting flag of (?i) will be evaluated.

info

KurocoEdge utilizes Rust's regex syntax.
For more technical details, refer to Rust's regex grouping and flag documentation.

7. Pattern explanation (optional)

regex101 provides an "Explanation" panel next to the regex pattern. This panel displays the explanation of each element in the regex pattern and provides insights into the matching process.

If you want to understand the meaning of each element and get an explanation of the matching process, refer to this panel. Image from Gyazo

8. Use sample regex patterns and text

regex101 allows you to use pre-existing sample regex patterns and text. You can select common regex patterns and example texts from the "Samples" menu at the top of the website.

This makes it easy to perform tests on specific patterns or texts.

These are the basic steps for using regex101. It is a powerful tool for testing and debugging regular expressions, so make sure to take advantage of it.


Support

If you have any other questions, please contact us or check out Our Discord Community.