RegExes in Ruby — A Brief Summary

Me when I see a RegEx

This is a brief overview of the Ruby class Regexp. However, regexes other languages (JavaScript, Python, etc) are similar.

There are 3 things we need to recognize to start understanding regexes.

What if we need to match the special characters?

Matching

We want {4} digits \d followed by -. All of that {3} times, ending with {4} digits \d.
dash_numbers looks for a dash followed by {4} digits \d
.match? is trying to find {16} digits \d in a row, and will just return “true” or “false”

Changing

chamelion.gsub(‘green’, new_color)
In both lines 3 and 5, we are just trying to match any lower-case vowels

Assigning Variables!

This is quite exciting
.scan returns every chunk of {4} digits \d

How else can regexes be useful?

What can regexes help you do?

Potential Problems

Resources

Full Stack Web Developer, former English as a foreign language teacher and volleyball coach. All views and opinions are my own.

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store