You can try and use regular expressions! Introducing RegExr
Hello.
I'm Mandai, in charge of Wild on the development team.
Regular expressions are often used during development, and if you write random regular expressions, there is a possibility that you may end up with a shocking bug.
So, if you want to test regular expressions or check their operation, but don't want to write test code, I'd like to introduce you to some useful sites.
Let's use RegExr to check regular expressions
There is a site called RegExr
This site has a lot of useful functions for checking regular expressions, and I think it's easy to use.
Originally, it was a site where you could check only JavaScript regular expressions, but recently, while I wasn't looking, it also supported PHP regular expressions (PCRE).
It's easy to use, and there are some parts that you can understand just by looking at them, but since the entire site is in English, I'd like to go through them one by one.
Menu
The menu includes site help and regular expression cheat sheets.
In particular, you'll be looking at cheat sheets and references often, so it's a good idea to memorize them.
It is useful because it is designed to be easy to read.
Expression
From here, we will write the actual regular expression in the Expression section, which is a frequently used item.
Since it is basically JavaScript, you will need to write the regular expression between "/" and the part enclosed by "/".
The parts surrounded by "()" and "[]" are color-coded, making it very easy to understand visually.
I would like this kind of functionality to be added to VSCode as well...
On the right side of the title, you can select either JavaScript or PCRE as the regular expression execution engine.
You can also choose from 5 options under Flags.
- g (global)
- i (case insensitive)
- m (multiline)
- u (unicode)
- y (sticky)
Each option can be set using JavaScript, so for example in PHP, there is no global flag, so you will need to select a dedicated function called preg_match_all.
Text
Enter sample text in this field.
Various things are written by default, but you can delete them or enter them yourself.
Enter any suspicious strings or strings you want to test.
Tools
This item contains a set of tools for cooking the results of regular expressions, and the following four are currently available.
Replace
A tool for replacing strings matched by regular expressions.
This tool allows you to perform simple string transformations, so it can be used as more than just a regular expression checking tool.
List
List displays a list of strings matched by a regular expression.
The matched string will be placed in the part displayed by "$&", so you can add the string you want to add all at once by entering the string you want to add before and after the extracted string.
By default, "\n" is added, so each matched string is added to a new line, but if you add "-" to the beginning of the string, you can make the matched strings into a markdown list. It's also easy to do.
This is convenient.
Details
The tool Details allows you to know in detail which part of the regular expression the selected string matches.
It's possible that you're only getting the expected result because you matched in a part that wasn't what you expected, so check here to make sure the process is working correctly.
Explain
This is a feature similar to MySQL's EXPLAIN. You can see which strings are grouped by parentheses, and which parts of the strings are matched by the parentheses.
This is also very useful.
summary
We introduced the functions of RegExr, a regular expression checking tool, but what did you think?
With recent updates, it has become more and more convenient, with support for PHP and the addition of tools that allow you to do more than just check regular expressions.
Personally, I often use Excel to use the Replace and List tools, so I thought I'd try working a little more intelligently.
That's it.