Trovare email e URL
Estrarre informazioni di contatto dal testo disordinato
Trovare email e URL è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NLP Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NLP Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 🔍
Domande Frequenti
La lezione «Trovare email e URL» è gratuita?
Sì — il testo completo di «Trovare email e URL» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NLP Academy, passa a CoddyKit PRO. Il corso NLP Academy include 4 lezioni in totale.
Cosa imparerò in «Trovare email e URL»?
Estrarre informazioni di contatto dal testo disordinato Eserciti NLP Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare NLP Academy?
Non è richiesta alcuna esperienza precedente. NLP Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Trovare email e URL»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione NLP Academy?
Sì. Ogni lezione NLP Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Le espressioni regolari in 5 minuti
- Trovare email e URL
- Gruppi di cattura e sostituzioni
- Trucchi per la tokenizzazione con regex