Module lessons (3/4)
Extracting URLs and IPs
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}\band know when to delegate the check0..255to 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
- 1Mental model: breaking down into pieces + refinement into code
- 24 progressive examples step by step
- 3Guided practical exercises
- 4Quick check
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.