DEV Community

Kimberly Kohel-Hayes
Kimberly Kohel-Hayes

Posted on • Updated on • Originally published at

Creating a Custom RegEx

Want to have a little programming fun? Let's create a RegEx! What is a RegEx? Well funny you should ask that! A RegEx or Regular Expression is a search string of condensed datum. Let's say you wanted to search for all capital letters in a given set of text. How would you go about it? A RegEx. This post will explore creating a RegEx for few different situations.
Before we start, three resources that will help anyone trying to build a RegEx are the following websites:
Ruby Docs Regexp
starts_with_a_vowelLets walk through method


and the steps I used to successfully find a working RegEx. We'll start by picking out a list of words. Find some that are capitalized and some that are not. Pick at least one, or more that starts with each vowel, capitalize some and leave some lower-case. Pick out a few words that start with consonants. Throw in some punctuation. Maybe some numbers. Now we have our list. Go to either Regexr or Rubular and enter your list in the text area. Make sure that you delete any sample text that was there already. In the RegEx area (which you might have to delete as well) you start entering possibilities. Play with it. Both sites give you plenty to go on. See if you can solve it differently than I did.
Now let's do something a little more complicated! Let's see if we can match all valid phone numbers but kick out all invalid phone numbers! You are really going to have to use your imagination and maybe do some research on this one! Here's what I came up with.valid_phone_number
I hope you have some fun with this programming problem.

Top comments (0)