简体   繁体   English

使用 python 自动化无聊的东西中电话号码的正则表达式

[英]Regex for Phone Numbers in Automate the boring stuff with python

what does this code mean?这段代码是什么意思? (\d{3}|\(\d{3}\)) ? (\d{3}|\(\d{3}\)) I understand that (\d{3}) means that the digit is repeated 3 times, but I don't understand the rest of it.我了解 (\d{3}) 表示该数字重复 3 次,但我不了解它的 rest。 Can someone please explain有人可以解释一下吗

"(\d{3}|\(\d{3}\))"

What an eye- capturing regex hm?多么capturing的正则表达式啊?


Let's do this one by one.让我们一一进行。

\d{3} means "match any number that occurs three times." \d{3}表示“匹配任何出现三次的数字”。

\( or \) means "match the literal parenthesis, but this has no special meaning at all." \( or \)表示“匹配文字括号,但这根本没有特殊含义”。

| means "match the previous statement OR the next statement."意思是“匹配上一条语句或下一条语句”。

( with ) means "match the regex inside me and capture/remember them." ( with )表示“匹配我内心的正则表达式并捕获/记住它们。”


TL;DR TL;博士

Match a 3-digit number or a 3-digit number inside parentheses and capture/remeber the match.匹配括号内的 3 位数字或 3 位数字并捕获/记住匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Strip() 的正则表达式版本 - 用 Python 自动化无聊的东西 - Regex Version of Strip() - Automate the Boring Stuff with Python 第 9 章用 python 自动化无聊的东西 - Chapter 9 automate the boring stuff with python 第 7 章,使用 Python 将无聊的东西自动化,练习项目:strip() 的正则表达式版本 - Chapter 7, Automate the boring stuff with Python, practice project: regex version of strip() 尝试将 RegEX 与“使用 Python 自动化无聊的东西”中的 Excel 练习结合起来 - Trying to incorporate RegEX with Excel exercise from "Automate the Boring Stuff with Python" 自动化无聊的东西第7章:正则表达式 - 电话号码和电子邮件提取器仅提取电话号码 - Automate the Boring Stuff Chapter 7: Regular Expressions - phone number and email extractor only extracting phone numbers 正则表达式搜索自动化无聊的东西,功能和错误 - Regex Search Automate Boring Stuff, functions and errors 使用 Python randomQuizGenerator 错误自动处理无聊的事情 - Automate the Boring Stuff With Python randomQuizGenerator Errors 使用Python Ch 4 myPets自动执行无聊的工作 - Automate The Boring Stuff with Python Ch 4 myPets 使用Python自动执行无聊的工作:嵌套字典和列表 - Automate the Boring Stuff with Python: Nested Dictionaries and Lists 用 Python 自动化无聊的东西 - 逗号代码 - Automate the Boring Stuff with Python - Comma Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM