Open Refine:使用正则表达式拆分列,其中包含由“And”连接的 2 个或多个名称

问题描述

如何使用正则表达式拆分列,其中包含 2 个或多个名称,并由“And”连接。例如,“Jonathan And Betty”应该分成两个单独的列,分别包含 Jonathan,Betty。但是,我不想将名字拆分为 Ander、Andrew 或 Andy。

解决方法

在不知道确切的边缘情况的情况下,您应该能够使用诸如“(\w*)( And )(\w*)”之类的东西来进行匹配,使用“$1,$2”来替代。它不会匹配名字 Ander,因为例如,'And' 和 'er' 之间没有空格。但它将匹配您给出的正例,并且第一组匹配将被第二组匹配用替换中指定的逗号分隔。

这是 Javascript 中的一个小提琴示例:https://jsfiddle.net/s78wp5fz/

const tests = ["Jonathon And Sue","Anders and Mitchandre"];
const out = tests.map((test) => test.replace(/(\w*) [Aa]nd (\w*)/,'$1,$2'))
console.log(out);
,

转到列菜单,选择菜单项 « 分成几列... »

menu item « Split into several columns... »

输入此正则表达式分隔符:\s+(?i)and\s+ (它将捕获大小写的所有变体,使其不区分大小写。)

Dialog for the Split command.

这是你的最终结果:

enter image description here

问候, 安托万