0Pricing
NLP Academy · Lesson

Finding Emails and URLs

Extract contact info from messy text.

Finding Emails and URLs is a free NLP Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Patterns Hide in Messy Text

Real text is full of structured snippets like emails and links. Regex lets you pull these out automatically, even from long, messy documents.

What an Email Looks Like

An email has a name, an at sign, a domain, and an extension. Spotting that shape is the first step to writing a pattern for it.

A Simple Email Pattern

This email pattern grabs word characters, an at sign, more characters, a dot, and letters. It is not perfect, but it catches most real addresses.

re.findall("\w+@\w+\.\w+", "hi a@b.com")

Why the Dot Needs Escaping

In a domain you want a literal dot, not the any-character dot. So you escape it as \. to match only a real period in the address.

Extracting Many Emails at Once

Pair your email pattern with re.findall to sweep an entire document and return every address it contains as a clean Python list.

emails = re.findall(pattern, text)

What a URL Looks Like

A URL usually starts with http or https, then ://, then a domain and path. That predictable start makes it a great target for regex.

A Starter URL Pattern

This URL pattern matches http or https, then any non-space characters. The optional s after http is written with a question mark quantifier.

re.findall("https?://\S+", text)

Optional Parts With the Question Mark

The question mark makes the part before it optional. In https? the s may or may not be there, so both http and https match cleanly.

Greedy Matching Can Overreach

By default quantifiers are greedy and grab as much as they can. With URLs this can swallow trailing punctuation you did not want.

Tame It With Boundaries

Use \S to stop at the first space, or trim the result afterward. Knowing where a match should end keeps your extraction tidy.

Test on Real Samples

Always test your pattern on messy real text. Edge cases like plus signs in emails or query strings in URLs reveal where it still leaks.

Quick Check

You want http to be optional in the s only. Which symbol makes the preceding character optional?

Recap: Pulling Out Contact Info

You built patterns for emails and URLs, escaped literal dots, and used the question mark for optional parts. Now you can mine contact info from text. 🔍

Frequently asked questions

Is the “Finding Emails and URLs” lesson free?

Yes — the full text of “Finding Emails and URLs” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Finding Emails and URLs”?

Extract contact info from messy text. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start NLP Academy?

No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Finding Emails and URLs” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this NLP Academy lesson?

Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Regex in 5 Minutes
  2. Finding Emails and URLs
  3. Capturing Groups and Replacements
  4. Regex Tokenization Tricks
← Back to NLP Academy