如何在字符串中搜索第一次出现的“:/”,然后搜索所有其他出现的包含“:/”的子字符串?

How to search a string for 1st occurrence of ":/" and then search all other occurences of the found substring inclusive ":/"?

一点解释:

我有一个字符串(来自命令行程序执行kpsewhich -all etex.src):

c:/texlive/2019/texmf-dist/tex/luatex/hyph-utf8/etex.srcc:/texlive/2019/texmf-dist/tex/plain/etex/etex.src

此字符串由 2 个或多个串联的文件路径组成,这些文件路径将再次分开。

动态搜索模式:c:/

文件始终位于同一卷上,此处为 c,但必须确定卷名。

是否可以用 RegExp 做这样的事情?

我可以根据实际文件名拆分字符串 etex.src,但是其他方法可行吗?

更新:

RegExp如下

(.+?:[\/\]+)(?:(?!).)* 

更符合我的要求。

我猜这个表达式可能会有点接近您可能想要设计的内容:

c:\/.*?(?=c:\/|$)

DEMO

我不完全确定你想要这个 RegExp 检索什么,但如果你想获取文件路径数组,那么你可以使用 /(?<!^)[^:]+/g regex:

// in node.js
const str = 'c:/texlive/2019/texmf-dist/tex/luatex/hyph-utf8/etex.srcc:/texlive/2019/texmf-dist/tex/plain/etex/etex.src'
const paths = str.match(/(?<!^)[^:]+/g)
// [
//   "/texlive/2019/texmf-dist/tex/luatex/hyph-utf8/etex.srcc",
//   "/texlive/2019/texmf-dist/tex/plain/etex/etex.src"
// ]

此 RegExp 搜索不包含 : 且不从字符串开头开始的符号序列(这不包括 c 卷或任何其他卷名称)