[英]How to search a string for 1st occurrence of “:/” and then search all other occurences of the found substring inclusive “:/”?
A little explanation: 一点解释:
I have a string like (from a commandline programm execution kpsewhich -all etex.src
): 我有一个字符串(
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
This string consists of 2 or more concatenated file paths, which are to be separated again. 此字符串包含2个或更多串联的文件路径,这些路径将再次分开。
Dynamic search pattern: c:/
动态搜索模式:
c:/
The files are always on the same volume, here c
, but the volume name has to be determined. 文件始终位于同一卷上,这里为
c
,但是必须确定卷名。
Is it possible to do something like this with an RegExp? 是否可以用RegExp做类似的事情?
I could split the string according to the actual filename etex.src
, but is the other approach possible? 我可以根据实际的文件名
etex.src
拆分字符串,但是其他方法可行吗?
Update: 更新:
The RegExp as follows RegExp如下
(.+?:[\/\\]+)(?:(?!\1).)*
meets my requirements even better. 更好地满足了我的要求。 How to disassemble a string with CaptureGroup?
如何使用CaptureGroup反汇编字符串?
I'm not entirely sure what you want this RegExp to retrieve but if you want to get the array of file paths then you can do it with /(?<!^)[^:]+/g
regex: 我不确定要让此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"
// ]
This RegExp searches for a sequence of symbols which don't include :
and which don't start at the beginning of the string (this excludes c
volume or any other volume name) 此RegExp搜索不包含
:
并且不在字符串开头的符号序列(不包括c
卷或任何其他卷名称)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.