gpt4 book ai didi

java - 获取所有唯一的文件名

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:27:39 25 4
gpt4 key购买 nike

作为序言,我是正则表达式的初学者。我有一个看起来像这样的字符串:

     my_folder/foo.xml::someextracontent
my_folder/foo.xml::someextracontent
another_folder/foo.xml::someextracontent
my_folder/bar.xml::someextracontent
my_folder/bar.xml::someextracontent
my_folder/hello.xml::someextracontent

我想返回属于 my_folder 的唯一 XML 文件。所以正则表达式将返回:

my_folder/foo.xml
my_folder/bar.xml
my_folder/hello.xml

我看过Extract All Unique Lines这接近我的需要,但我不确定从那里去哪里。

我得到的最接近的尝试是 (?sm)(my_folder\/.*?.xml)(?=.*\1) 它获得了所有重复项,但我想要相反的结果,所以我尝试做一个否定的前瞻而不是 (?sm)(my_folder\/.*?.xml)(?!.*\1) 但是捕获组是完全错误的。

我的正则表达式中缺少什么?这是正则表达式的链接:https://regex101.com/r/ggY2RB/1

最佳答案

This RegEx可能会帮助您找到您可能正在寻找的唯一字符串:

/(\w+\/\w+\.xml)(?![\s\S]*\1)/s

enter image description here

如果你只想匹配my_folder,你可以试试this :

 /(\my_folder\/\w+\.xml)(?![\s\S]*\1)/s

enter image description here

关于java - 获取所有唯一的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55643124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com