Week 7

Watch on YouTube

A pattern that finds a video id inside a few link shapes.

You type

A link.

The tool
Find the id inside the link A link Find the id An embed link, or nothing
What comes out

An embed link, or silence when the link is not one of those shapes.

The question, more slowly

The question is: a YouTube link comes in, and if it is one of the shapes the spec lists, you print an embed link built from the video id. If it is not one of those shapes, you print nothing.

The id is the piece you capture. The rest of the pattern describes the surroundings: the host, the path, the query. There are a few legal shapes, so you either allow each or you find what they share.

People grab too much, such as the whole query string, or they reject a short youtu.be link that the spec allows. Circle the id on paper for each sample link first.

Before you code

Copy one real link from the spec onto paper and circle the id. The pattern's job is to find that circled part.