引导式测验 · 中等 等级
如何使用 AI 测验编写正则表达式
检查您对人工智能描述模式、正则表达式锚点和 RE2 等风格的掌握,以及测试贪婪匹配和灾难性回溯。
问题 1 的 8
为什么没有锚点的 \d{5} 不是验证邮政编码的好模式?
预览每个问题8 问题
当您参加测验时,就会出现答案和解释。
- 为什么没有锚点的 \d{5} 不是验证邮政编码的好模式?
- It only matches letters, not digits
- It can match five digits inside a longer string like "1234567"
- It is invalid syntax in most engines
- It requires a special Unicode flag to work
- 对 AI 的良好正则表达式请求应该包含什么?
- A request for the shortest possible pattern
- The name of your company and project
- A promise that you will test it later
- Examples that should and should not match, plus the regex flavor you use
- Google Sheets 使用 RE2 引擎。RE2 刻意省略了什么?
- Backreferences and lookaround
- Character classes like [A-Z]
- Anchors like ^ and $
- Quantifiers like + and *
- 什么是灾难性回溯?
- A regex running out of memory on very short strings
- A regex tester highlighting the wrong characters
- Exponential slowdown on patterns like (a+)+ when input almost matches
- A regex that always returns an empty match
- 应用于文本“<a><b>”时,贪婪模式 <.*> 匹配什么?
- Only "<a>"
- Nothing at all
- Only "<b>"
- The whole string "<a><b>"
- What does the guide suggest for validating email addresses?
- Use one perfect regex that implements the full email standard
- Use a simple sanity check plus a confirmation email
- Never validate email addresses at all
- Rely on lookbehind to check the domain
- For parsing HTML, JSON or other nested structures, what does the guide recommend?
- A longer and more detailed regex
- Using lazy quantifiers everywhere
- A real parser built for that format
- Switching to the RE2 engine
- Which Python function requires the entire string to match the pattern?
- re.fullmatch
- re.search
- re.findall
- re.sub