DEV Community

jun
jun

Posted on

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! 🚀

Top comments (0)