Skip to main content
Module 8 · Lesson 3 of 431/32 in the course~18 min
Module lessons (3/4)

Extracting URLs and IPs

Lesson preview5 hands-on exercises readyRegex Course · Module 8 — Practice

Recognize http(s) URLs and IPv4 addresses in free-form text.

What you'll learn in this lesson

  • Extract HTTP/HTTPS URLs consisting of optional scheme s, host, optional port and path.
  • Build the pragmatic pattern for IPv4 addresses \b(?:\d{1,3}\.){3}\d{1,3}\b and know when to delegate the check 0..255 to the code.
  • Avoid capturing trailing punctuation (., ,, )) when extracting URLs from conversational text.

Overview

URLs and IPv4 addresses are often hidden in application logs, comments, or text dumps. Writing a clean pattern for both requires a balance between tolerance (capturing all the real variations) and precision (not dragging around parentheses or full stops).

Rather than looking for a single giant regex that also validates the 0..255 octets and each URI RFC, use a readable extraction regex to match the candidates, and then refine the extracted values in JavaScript (e.g. new URL() or split('.').every(n => n <= 255)).

Sections covered in this lesson

  1. 1Mental model: breaking down into pieces + refinement into code
  2. 24 progressive examples step by step
  3. 3Guided practical exercises
  4. 4Quick check
Pro Lesson · Module 8 — Practice

Unlock "Extracting URLs and IPs" and the full Regex Course curriculum

Recognize http(s) URLs and IPv4 addresses in free-form text.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Regex Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.