Regex in short

I am a software developer and project manager; passionate about solving problems through IT.
Search for a command to run...

I am a software developer and project manager; passionate about solving problems through IT.
No comments yet. Be the first to comment.
The realm of Brain-Computer Interfaces (BCIs) is rapidly evolving, promising to revolutionize human-computer interaction. From medical applications like restoring mobility and communication to entertainment and cognitive enhancement, BCIs are poised ...
If you’re into Technical Writing or a member of any tech community, you’ve probably heard of the buzzword “DevRel.” It’s strange and confusing how so many job roles have been introduced into the world during this information age, and even confusing t...
Web scraping is an automatic method to obtain large amounts of data from websites. The data is largely unstructured and can be further refined. In this article, we will be testing the desktop application Scrape Any Website as an exercise for the HNGi...
Java is a multi-platform, object-oriented, and network-centric language. Spring Boot is an open-source Java-based framework used to create a microservice. It provides a good platform for Java developers to develop stand-alone and production-grade spr...
Going straight to coding without a ‘definite’ idea of what your app should look and feel like is very risky and can lead to unnecessary rework. It’s therefore necessary to plan a roadmap or process flow. This does not mean you have to have it all pla...
Regex, short for regular expression, is a sequence of characters that define a pattern. It is very powerful and used in string manipulation, validation and search. By default, regex is embedded in every programming language.
Using regex can be confusing. As such, it's important to know your expectation before attempting to implement it. Regexr is an online tool to evaluate regex. Open this in another tab while following through this article.
A) Expression Pattern: Brackets are used to find a range of characters.

B) Metacharacter: Metacharacters are characters with a special meaning.

C) Quantifiers: Define quantities.

"123".search(/^[a-zA-Z]+$/) // false=> Capital and small letters required
"AaBbCc".search(/^[a-zA-Z]+$/) // true
"123".search(/./) // true => Any character
"123".search(/^[0-9]{10}/) // false=> Numbers with a count of 3`
"1234567890".search(/^[0-9]{10}/) // true => Numbers with a count of 10
"01-01-2020".search(/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/) // true => Date format: dd-mm-yyyy or dd/mm/yyyy
"Password1!".search(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!_`,/@#\-"=:;~<>'\$%\^&\*\?\|\+\(\)\[\]\{}\.])(?=.{8,})/) //true => Password of 8 characters including numbers, letters and symbols
Note: Using .search() produces a 0 or -1 result. 0 represents true while -1 represents false.

Now that you've gotten a taste of regular expressions, you can try them on your own, delving into more complicated patterns.
If you like this article, feel free to comment and share. You can also reach out to me on Twitter | LinkedIn | Github
Ciao👋🏼