What are Regular Expressions (Regex) and how to learn them quickly?

“Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.”

This is a regular expression. Yes, you are right. It looks vied. So, if you are still with the mindset of learning Regular expression easily and quickly, first of all, you have to say goodbye to that thought.

This is one of the most wanted technology skills that has been so important in the tech field, has been unfortunately ignored by not only beginners but also by intermediated developers as well.

So, if you are still reading this article, it seems how you are enthusiastic about Regular Expression after a frustrating introduction.

Through this article, I will explain what Regular Expression is, how powerful this is, what real-world use cases are, what programming language you do need to learn in order to use Regular expression, and how to get started as a crawler.

In addition, you will have some important instructions and resources that you want to learn this.

What is Regular Expression?

Regular Expression is a sequence of characters that constructs a search pattern.

https://en.wikipedia.org/wiki/Regular_expression

When you are searching for data in a document, you can use these search patterns to find out what you are looking for.

Here is one important key point that you need to know is, the programming community does not refer to this as Regular Expression because of its’ mouthful ness. Usually, they use “Regex” instead of Regular Expression. So here from, I also use the term Regex.

How powerful Regex is?

As I mentioned earlier, Regex is essentially a method(tool) for pattern matching. For example, when you open an MS Office file or browser, you press Ctrl+F and just start typing to search for things and manipulate some tasks like find and replace.

Regex use cases

Regex is a basic of search engines, search and replace dialogs of word processors and text editors, and many other advanced concepts like Pattern recognition in Machine learning and so on.

Although search engines utilize this method effectively, most of the other tools and features are still relatively new to SEO tools.

Here are few other use cases that we can find frequently using regex formulas.

As a web crawler, learning slightly the basics of Regex is also extremely helpful for identifying errors, extracting whatever data you want from your own documents (not all), create verification tools for matching passwords, E-mails, and credit card numbers according to a format.

Also, you will be able to check command lines, web server logs, test results, and passing user inputs and various text files.

Apart from that, if you are really interested in SEO, Cyber Security, and many other advanced technologies, Regex is a fine thing to learn and you will be exposed to things that nobody has ever exposed.

Isn’t it amazing?

Despite the availability of Regex is huge, the power of this method is not utilized by many developers because of the complexity.

So, somehow if you would be able to familiarise yourself with this tool once, you are going to be a superhero.

what programming language you do need to learn and how long does it take?

That really depends on what you are going to do with Regex.

In case that you are expecting to learn Cyber Security, System Security, Network Administration, or any other advanced concepts, then it is super helpful for you to spend some time with that, it may be few months.

But if you are a regular web developer or Mobile App developer, you do not need to go into dept,

Also, another important fact is that Regex is not a programming language. It is just a developed technique.

Most of the popular programming languages have this feature by default and sometimes, you may have to install some packages. You can learn Regex with any programming or scripting language that you are familiar with.

How you can Lean Regex

As I mentioned above, Regex is a somewhat complex method that you need to learn consciously and practice continuously.

So, here I suggest some free sources that you can refer to to get a basic idea about Regex and practice it.

· RegEXr

· developer.Mozilla

· Regex Golf

To touch with the surface of Regex, I especially recommend regex.com.

https://regexr.com/

Here are some reasons for that.

1. You can see a quick start guide on the left-hand side, so you can learn about Regex and remind while scripting with Regex.

2. On top of that you may give instructions.

3. Also, it can easily handle the differences in different languages and help you to overcome them.

4. The most important thing is that Regexr has a good community and you can get any support from there.

5. There, you can find out many prebuild Regexes.

Now, you are going to understand how this comes together with a simple example. Then you will be able to use this powerful tool in real-world scenarios.

Example

Password Validation

Validate the format of a password for a signup form? Let’s force passwords to contain a capital letter, lowercase letter, number, and min length of 8

Regex script
const re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/g

"1sMyPasswordOK?".search(re);

Explanation

‘^’ Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled. This matches a position, not a character.

Matches a (group) after the main expression without including it in the result.

const re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/g ;

const re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/g ;

const re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/g ;

const re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/g ;

const re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/g ;

const re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/g ;

So, I assume that you might get an idea about how Regex works.

Instructions

Finally, I must give you some instructions.

Please be conscious while using Regex with the web. Sometimes you may get into legal troubles as well. If you try to get data from a website unauthorizedly it is not allowed, and they will get legal actions against you.

If you want to use some data from other websites, you may have to use their APIs.

Here some resources that you can use SEO for your websites, without creating your own search algorithms. Many search engines offer APIs or other interfaces that allow search results to be directly downloaded into applications for further processing, such as Yahoo! Search Web Services (http://developer.yahoo.com/search/) or Google AJAX Search API (http://code.google.com/apis/ajaxsearch/).

You can use Regex for data validation but be careful while using it to scrape data from other websites.

Another red alarming thing is that Do not use Regex on Android or IOS Apps.

You may get banned from Apple and Google. Because IOS checks for many policies before accepting your Apps. But in Android, it is easy to submit an app on the play store. However, if google finds untheorized things inside your app, they will band not only your accounts but also all other published apps.

Summary

Patterns are all over the web. Using regex, you can locate instances of patterns and extract relevant data.

Regular expressions are not simple to familiar, but once you get started you’ll find unlimited uses for this powerful technology.

Thank you for reading.

--

--