V2EX  ›  英汉词典

Capturing Group

释义 Definition

正则表达式(regex)中,“capturing group(捕获组)”指用圆括号 (...) 包起来的子表达式,它不仅用于分组与限定作用范围,还会把匹配到的内容保存为可引用的结果(如通过反向引用 \1\2,或在编程语言中通过 group(1) 等方式取出)。也常见命名捕获组(如 (?<name>...))。另有“非捕获组” (?:...) 不会保存匹配结果。

发音 Pronunciation (IPA)

/ˈkæptʃərɪŋ ɡruːp/

例句 Examples

I used a capturing group to extract the year.
我用一个捕获组把年份提取出来。

In the pattern (\w+)\s+\1, the capturing group stores the first word so the regex can match the same word again via a backreference.
在模式 (\w+)\s+\1 中,捕获组保存第一个单词,使正则可以通过反向引用再次匹配同一个单词。

词源 Etymology

“Capturing”来自动词 capture(捕获、抓取),强调“把匹配到的内容抓住并保存”;“group”表示“分组”。合起来就是“把一段匹配结果作为一组保存起来”,以便后续引用或提取。

相关词 Related Words

文学/著作示例 Notable Works

  • Mastering Regular Expressions(Jeffrey E. F. Friedl)
  • Regular Expressions Cookbook(Jan Goyvaerts, Steven Levithan)
  • Introducing Regular Expressions(Michael Fitzgerald)
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1698 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 04:20 · PVG 12:20 · LAX 20:20 · JFK 23:20
♥ Do have faith in what you're doing.