题目
ECON3310001.1251 Quiz 10: Regular Expressions
多项选择题
Identifying Address Patterns in Regular Expressions Regular expressions (RegEx) are commonly used to extract structured data from text. When searching for addresses, a pattern must account for elements such as street numbers, street names, city names, state abbreviations, and ZIP codes. Which of the following RegEx patterns would yield the best results if you want to identify U.S. addresses?
选项
A.^\d+\s[A-Za-z\s]+,\s[A-Za-z\s]+,\s[A-Z]{2}\s\d{5}(-\d{4})?$
B.^[A-Za-z0-9_.+-]+@[A-Za-z0-9-]+\.[A-Za-z]{2,5}$
C.^\(\d{3}\)\s\d{3}-\d{4}$
D.^@[A-Za-z0-9_]+$
E.^\d{4,5}$
查看解析
标准答案
Please login to view
思路分析
We’re evaluating which RegEx patterns best identify U.S. addresses and we’re given several options to consider.
Option 1: ^\d+\s[A-Za-z\s]+,\s[A-Za-z\s]+,\s[A-Z]{2}\s\d{5}(-\d{4})?$
- This pattern matches a typical U.S. street address format: a numeric street number, followed by a street name, then a comma, a city name, another comma, a two-letter state abbreviation, a space, and a five-digit ZIP code with an optional 4-digit ZIP+4 extension. It captures the essential components of a standard address and uses anchors to ensure the entire string matches, which helps prev......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
Question at position 22 Which of the following strings match(es) the regular expression in following command? grep “^[ABCa-z][23]” Notes.TXT ABCa-z2345x22345Ba32ABCAll of these.
Are the languages of the following regular expressions the same? (a|b)*(ab)* (a*|b*)*(ab)*
Are the languages of the following regular expressions the same? (a|b)* (b|a)*
Are the languages of the following regular expressions the same? a(bc)* ab*c*
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!