0Pricing
NLP Academy · 课时

查找电子邮件地址与网址

从复杂文本中提取联系信息

查找电子邮件地址与网址 是 CoddyKit 上的免费 NLP Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 NLP Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 NLP Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

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. 🔍

常见问题解答

「查找电子邮件地址与网址」课时是免费的吗?

是的 — 「查找电子邮件地址与网址」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 NLP Academy 课程的其余内容,请升级到 CoddyKit PRO。 NLP Academy 课程共包含 4 节课。

「查找电子邮件地址与网址」这节课中我会学到什么?

从复杂文本中提取联系信息 你通过在浏览器中直接运行的动手代码来练习 NLP Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 NLP Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 NLP Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「查找电子邮件地址与网址」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 NLP Academy 课中编写并运行代码吗?

能。每节 NLP Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 5 分钟掌握正则表达式
  2. 查找电子邮件地址与网址
  3. 捕获组与替换
  4. 正则表达式分词技巧
← 返回 NLP Academy