February 1

How to Learn and Use Regular Expressions (Regex)

1  comments

Whoever would have thought that something that looks like gibberish would actually have such powerful usages. Look at this example:

\d\d[/]\d\d[/]\d\d[ ][-][ ]

Would you believe that it’s actually an expression that matches anything of the format of “12/06/08”? Amazing.

I’ve been putting off learning about regular expressions (regex) for the longest time because it seems overly complicated — but I was forced to learn more about it after a recent application demanded of it. And boy was I glad to have finally jumped into it — it’s simply one of the best ways to search for any text pattern.

With regular expressions, you can search for any number of characters, specify whether it’s a number or letter, and even specify a range, like only accept alphabets between B and E. Or only numbers from 1-5.

So if you think about it, the sample regular expression string up there can actually be improved upon. For instance, since the date format is dd/mm/yy, we know that dd can go higher than 31, nor can it go lower than 1. And similarly, we know that for mm, it’s between 01 to 12. The tricky part is yy, because it can vary, depending on how you’re going to use this date. If your application’s more geared towards the future, then keeping the first digit to 0 or 1, and the 2nd digit from 0 to 9 should be just fine.

So as you can see, if you’re a developer, then regular expressions (regex) should be something that you are very familiar and comfortable with, because it makes your life so much easier!


Other posts about scaling up businesses

I Only Own One Pair Of Shoes

Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Super Scale Your Business Today

Get on a personal call with me so that you can Super Scale your business now

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"62516":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default Palette","value":{"colors":{"62516":{"val":"var(--tcb-skin-color-0)"}},"gradients":[]}}]}__CONFIG_colors_palette__
Super Scale Your Business Now