![](/img/trans.png)
[英]How to Search a JavaScript Collection for the 1st Occurrence Between Multiple Phrases?
[英]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反汇编字符串?
我不确定要让此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.