A search function can be found on nearly every application to help the user find a text or even files from computer. The most basic search function is to search for the exact matching string which is very limited. The more advanced user would know how to use a wildcard by using an asterisk or question mark character in the search. For example, if the searcher is trying to find a text or file with the name raymond but he doesn’t know the full spelling, he could just search ray* which will return any results that starts with ray.
The most advanced algorithm for search would be regular expression, or some people just calls it regex. Regular expression is just a string that describes a search pattern. It can be very precise in the sense that you can use it to search for an email address format, a URL, or anything at all as long as you can define the correct regular expression. Hence it is often used in verifying input in a submission form, web scraping, htaccess redirects and etc.
Regular expression can be very interesting because the same purpose can be achieved using a different pattern. How the regular expression pattern is written is based on how good the person is in regular expression and also how specific you want it to be. Writing regular expression is not easy without learning it. So here are some resources that can help you analyze and write better regex pattern.
There is no need to waste your precious time in learning about regular expression if you just need a pattern, say for email verification in a form. All you need to do is just visit the Regular Expression Library website and search in their database that currently has 3420 regular expressions that’s free to use.
For example, you can find 38 different patterns that can be used to identify an email address format. You will need to read the description of the regex pattern and also check the sample of matching and non-matching data for a clearer picture.
2. Regex Hero
While there are so many online regular expression tools that provides real time highlighting of regex matches, Regex Hero is one of our favorite because it comes with a very useful benchmark feature. As we’ve said before that different regex pattern can be used to match a string, we can easily and quickly know which performs better using the benchmark feature found in Regex Hero.
As you can see from the screenshot above, the second pattern is 1,051.9% slower than the first pattern although they both matches a string of given text. Generally speaking, the longer regex runs faster. Regex Hero requires Silverlight to run.
RegexMagic is a shareware that helps to generate regular expressions without the need to know any of the regex syntax. While most people would advise that you should know regular expressions to write one, RegexMagic is probably the only tool that tries to get around this.
Do not think that RegexMagic will automatically generate regular expressions by itself. You will still need to learn how to use it because some parts of the program such as the different kinds of field and pattern matching might not be easily understood especially for beginners. Nevertheless, it is still easier than having to manually write a regex pattern by referring to a cheat sheet. The trial version of RegexMagic is fully functional for 7 days.
4. Online Regex Builder
While there are rarely any regular expression builder that automatically generates regular expression based on given data, SEQREL logXtender is the only one with a free online service that magically build a regex string to match the input.
This is probably what every person who wants to build a regular expression but doesn’t how to do it wants to use. The only problem with such automated regex builder is that the generated regex cannot be very precise, hence there might be a performance hit since it’s not optimized. Nevertheless, it is still a very good regex tool to quickly generate a working regex without knowing anything about it.
There are many online regular expression tools that are useful to analyze an existing regular expression to see if it matches a certain given text. With txt2re, it works the other way round where you provide the text and it tries to find recognizable patterns and allowing you to choose the available patterns to use.
To help you understand better in which pattern to select, you can move your mouse cursor on top of the underlined characters and it will show you if you’d like to match against a single character, match against double quote string, match against variable name and etc.