Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用Editpad Lite 7使用正则表达式删除重复项_Regex_Text - Fatal编程技术网

Regex 使用Editpad Lite 7使用正则表达式删除重复项

Regex 使用Editpad Lite 7使用正则表达式删除重复项,regex,text,Regex,Text,我在文本文档中有一个逗号分隔的单词列表。我基本上刚刚删除了一本小说中的所有标点符号,因此有很多相同单词的实例 我不知道如何使用正则表达式只留下每个单词的一个实例 我正在使用Editpad Lite 7 有人能给我一些建议吗。(如果可能)。如果您的编辑器支持,您可以使用它删除(即替换为“”)所有匹配项 (?<=,|^)([^,]*)(?=,)(?=.*,\1(,|$)) (?假设文本是逗号分隔的单词列表,如: hello,world,hello,abc,world 您希望删除重复的单词,

我在文本文档中有一个逗号分隔的单词列表。我基本上刚刚删除了一本小说中的所有标点符号,因此有很多相同单词的实例

我不知道如何使用正则表达式只留下每个单词的一个实例

我正在使用Editpad Lite 7

有人能给我一些建议吗。(如果可能)。

如果您的编辑器支持,您可以使用它删除(即替换为“”)所有匹配项

(?<=,|^)([^,]*)(?=,)(?=.*,\1(,|$))

(?假设文本是逗号分隔的单词列表,如:

hello,world,hello,abc,world
您希望删除重复的单词,以便生成的文本为:

hello,world,abc
我认为在Editpad Lite 7中使用正则表达式无法做到这一点。最好使用编程语言来实现这一点。下面是一个使用PHP的简单示例:

$text = "hello,world,hello,abc,world";
$seen = array();
foreach (explode(',', $text) as $word) {
    if (isset($seen[$word])) continue;
    $seen[$word] = true;
    print $word . ',';
}
// Outputs: hello,world,abc,

谢谢你的回答。我唯一熟悉的编程语言是Python,实际上我已经尝试用Python脚本来实现这一点。不过我放弃了。我会再试一次。