跟读练习: [Practice Problems] Regular Expressions (Regex) - Visually Explained - 通过视频学习英语口语

正在创建课程...
1
Have you tried our regular expressions practice exercises?
2
If you have, great!
3
We're going to work through the solutions now.
4
If not, the problems are linked in the description.
5
Alright, let's start with problem one.
6
In this problem, we want to match all the phone numbers from the bulletin board text.
7
Each phone number follows the format.
8
A fixed area code, and a hyphen, followed by three digits, another hyphen, and a final four digits.
9
Since every phone number starts with the same area code and hyphen, we write the literal characters 1, 2, 3, hyphen directly into the pattern box.
10
Next, the middle group of numbers can have any combination of three digits.
11
To match this, we use the character class 0 through 9 to match a single digit
12
and follow it with the quantifier 3 to match exactly 3.
13
Following the character class, we write another literal hyphen.
14
To match the last four digits, like the middle three, we use a character class with 0 through 9.
15
But to match four digits instead of 3, we use a quantifier of 4.
16
Great!
17
As we can see, this pattern matches both phone numbers and our bulletin board text.
18
Fixed quantifiers like 3 and 4 are ideal when you know the exact length you're looking for.
19
Phone numbers, zip codes, product codes, anything with a predictable structure.
20
Quantifiers will also be quite useful in problem 2.
21
In this problem, we want to write a regular expression to match all the prices in our text string.
22
each price starts with a dollar sign followed by one
23
or more digits a dot
24
and exactly two digits for cents you might be tempted to start by writing the literal dollar sign character
25
but in regex dollar sign is a special syntax
26
that means end of line
27
so it won't match the dollar sign character to match a
28
literal dollar sign we put a backslash in front of it after the dollar sign comes the digits before the decimal,
29
which we can match using a character class with 0 through 9.
30
Since there could be any number of digits before the decimal, we use the plus quantifier to match one or more digits.
31
Following this character class, we specify a dot.
32
Remember, like the dollar sign, the dot is special syntax, called a wildcard, that matches any single character.
33
To use a literal dot character, we need to write a backslash before it.
34
Finally, cents always have exactly two digits.
35
To match this, we write a character class allowing the digits 0 through 9 and a quantifier of 2.
36
Awesome!
37
With this pattern, all five prices are matched.
38
Before we move on, we've now written the character class containing 0 through 9 several times.
39
Since this is such a common pattern, regex syntax actually provides a shorthand for it.
40
Instead of explicitly writing the character class, we write backslash d, which also means any digit.
41
Awesome, our pattern is now more concise and we still get the same matches.
42
We'll use the digit shorthand backslash d again in problem 3.
43
In this problem, we want to match all the dates in the text.
44
Each date has a month name, a day number, and a four-digit year.
45
We'll start by matching the month names.
46
Month names are made up of letters, both upper and lowercase, so we'll use a character class of all the uppercase and lowercase letters.
47
To match one or more letters, we follow the class with the plus quantifier.
48
After the month name comes a literal space.
49
After the space, the day can be one digit or two.
50
To match exactly one or two digits,
51
we use the backslash d shorthand followed by a range quantifier with a lower bound of one and upper bound of two.
52
Following the day, we write a literal comma and space.
53
Lastly, the year is always four digits, so we write the digit shorthand and a quantifier of four.
54
Awesome!
55
With that pattern, we've matched all the dates.
56
With these practice problems, you've seen how to write patterns for three different data types.
57
If you want to go deeper on any of the concepts we used in this video, check out our regular expressions intro video linked in the description.
58
We're working on lots more Python explainer videos like this one, so be sure to subscribe so that you don't miss out.
59
If you have any questions or topics that you'd like to learn about, let us know in the comments below.
60
We'd love to hear from you.
61
Thanks for watching!

关于本课

在本课中,我们将通过实际练习来掌握正则表达式的应用。这包括匹配电话号码、价格和日期等常见格式。通过实践,我们可以学会如何使用正则表达式的语法来提取文本中的信息,从而提升我们的英语理解能力。这些内容不仅对提升英语发音有帮助,也能为雅思口语练习打下良好的基础。

关键词汇与短语

  • 正则表达式 - 一种用于匹配字符串的规则。
  • 电话号码 - 特定格式的数字串,用于联系。
  • 价格 - 带有货币符号的数字。
  • 日期 - 由月份、日期和年份构成的字符串。
  • 字符类 - 匹配特定类型字符的集合。
  • 量词 - 指定匹配字符的数量。
  • 通配符 - 用于匹配任何单个字符的符号。
  • 反斜杠 - 用于转义特殊字符的符号。

练习技巧

在进行英语影子跟读时,建议你跟随视频中的节奏来模仿练习。这种 shadow speak 方法能有效提高你的英语发音和流利度。视频所用的语速适中,非常适合进行逐字跟唱。当你听到每个正则表达式的构建时,尝试大声朗读并同时理解每个部分的功能。例如,听到“字符类”时,可以即时模仿发音,并同时理解其含义。通过这样的反复练习,不仅能帮助你更好地掌握正则表达式的概念,也能提升你在实际对话中的反应能力,为雅思口语练习提供更多支持。

在模仿过程中,可以多次暂停视频,确保听懂每个术语和其应用。逐渐加快跟读速度,挑战自己的发音和语调。有意识地练习可以帮助你在真实语境中更自信地使用英语。

什么是跟读法?

跟读法 (Shadowing) 是一种有科学依据的语言学习技巧,最初开发用于专业口译员的培训,并由多语言者Alexander Arguelles博士普及。这个方法简单而强大:您在听英语母语原声的同时立即大声重复——就像是一个延迟1-2秒紧跟说话者的影子。与被动听力或语法练习不同,跟读法强迫您的大脑和口腔肌肉同时处理并模仿真实的讲话模式。研究表明它能显着提高发音准确性,语调,节奏,连读,听力理解和口语流利度——使其成为雅思口语备考和真实英语交流最有效的方法之一。