How to Sort URLs into Nested Hashes with Regular Expressions

When it comes to parsing files that contain URLs, a common practice is to have the ability to group URLs by type. In this guide we walk through how to categorize links based on regular expressions.


Parse multiple markdown files and group URLs by keywords.

Exercise File

Code File

Exercise Description

Inside of multiple markdown files, you will find three types of URLs:

  • URLs that contain the word campsite in the URL string
  • URLs that don’t have the word campsite in the URL string
  • URLs that are not located on

In order to successfully complete this exercise, you will need to ignore all of the non URLs, and then group the other two types of URLs into their own nested hashes. Additionally, the markdown files have headings for each day. Utilize the humanize gem so that each day is its own key.

Example Input

There will be 4 full weeks with this type of formatting.

## Week 1
### Monday
- What we’ll learn today: *Setting up your computer with the right tools is the first step to becoming a great developer.  Setting goals will keep you on course and motivated as you go through this life changing experience.*
- [Code exercise](
- Workshop  [Environment Customization](
- Workshop  [Running Ruby on your system](
- Workshop  Bootcamp goal session
- Lecture   [The Developer Tipping Point](
### Tuesday
- What we’ll learn today: *Whether you plan to work as a freelancer or in a dev shop or for a company, planning is key to building out your applications.  We will learn about about tracking systems as we get started on our first app.  We will also be expanding our knowledge of ruby basics and discovering tools that we can use when coding with HTML.*
- [Code exercise](
- Workshop  [App Creation and Project Planning](
- Workshop  [Introduction to Ruby](
- Workshop  HTML skeleton: [Tools We'll Use in the Course](, [Structure](, [Head tag](
### Wednesday
- What we’ll learn today: *Building an application is a step by step process.  Keeping track of those steps is what version control is all about.  Git is a widely used version control system that will aid you in this process.  We will also discover how the ruby console can help you see what your code is outputting. Our HTML time will focus on page organization.*
- [Code exercise](
- Workshop  [Implementing Version Control](
- Workshop  [Ruby variables](
- Workshop  HTML tags + links: [Creating Page Components with the Div Tag](, [Implementing Inline Components with the Span Tag](, [Integrate Headings into Web Pages](, [Using Multi Line Content with Paragraph Tags](, [Working with HTML Hyperlinks](, [Adding PageBreaks with the Horizontal Rule Tag](, [Integrating Line Breaks into HTML Pages](
- Lecture   [Staying Sharp as a Developer](

Example Output

Day three’s (Wednesday’s) hash element should look like this:


Real World Usage

In real world development scenarios, a common task that you will be asked to complete is to build scripts to automate behavior. This specific exercise was a task I was handed a few days ago by the Devcamp development staff. In this guide you will need to work with: regular expressions, nested hashes, and functional programming.


Can be found on the solutions branch on github.

Jordan Hudgens

view all post
Leave a comment

Please be polite. We appreciate that.

By Daniele Zedda • 18 February


By Daniele Zedda • 18 February

Share on