capture group(捕获组):在正则表达式中,用圆括号 (...) 标记的一部分模式,用来把匹配到的子字符串“捕获/记住”,以便之后通过编号(如 \1)或名称(如 (?<name>...))引用,常用于提取、替换或复用匹配内容。(在不同语言/引擎中细节略有差异;另有“不捕获组”(?:...)。)
/ˈkæptʃər ɡruːp/
Use a capture group to extract the year from the date string.
使用捕获组从日期字符串中提取年份。
In the replacement, the second capture group is reused to keep the original file extension.
在替换时,会复用第二个捕获组来保留原始的文件扩展名。
capture 源自拉丁语 capere(“抓住、获取”),经由法语进入英语;group 源自意大利语 gruppo(“一组、一群”)。合起来在正则表达式语境中表示“把匹配到的一段内容抓取并作为一个组保存起来”。