繁体   English   中英

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

[英]How to search a string for 1st occurrence of “:/” and then search all other occurences of the found substring inclusive “:/”?

一点解释:

我有一个字符串( kpsewhich -all etex.src程序执行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如下

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

更好地满足了我的要求。 如何使用CaptureGroup反汇编字符串?

我猜想这个表达式可能与您可能要设计的表达式有些相似:

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

演示

我不确定要让此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卷或任何其他卷名称)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM