REGEXP & DATABASES

junlow

jun

Posted on November 3, 2019

REGEXP & DATABASES

Recently I am doing my 30-days-code challenge on HackerRank and came across this topic again. I wanted to share here what I have learned about so far.

I have a love-hate relationship with Regexp aka Regular expressions. My friends around me are either hate it or love it. My first thought before this was - wow, this is nice, no crazy functions, loops....but wait, the syntax, symbols are like crazy?

Alt Text

What the hell is Regexp?

This is a compact syntax means of describing a set of strings using a subset of common characteristics. For example, the common characteristics of aaa, aba, and aca are that they all start and end with the letter a.

Regular expressions add a layer of abstraction to strings that make it easier to search and manipulate text. While they can seem very confusing at first, however, the syntax for regular expressions is pretty standard across different programming languages.

Why use it?

For Data validation and Data extraction. Just like taking the information you wanted from a HUGE excel file. Regex reduces the pain to search a piece of data one by one from the databases. Pretty cool, huh

alt text

The Regexp class

Regular Expressions are class citizens in Ruby. They have their own class, which comes with its own built-in methods like match, scan, and gsub.

Regexp buddy

Here are some tools for using Regexp.

Further Read

This is the Documentation and guide for regex in Ruby.

alt text

Happy Regexing! 🚀

💖 💪 🙅 🚩
junlow
jun

Posted on November 3, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Use Bundler in a Ruby script
ruby Use Bundler in a Ruby script

February 26, 2023

REGEXP & DATABASES
ruby REGEXP & DATABASES

November 3, 2019