-1

A little explanation:

I have a string like (from a commandline programm execution 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.

Dynamic search pattern: c:/

The files are always on the same volume, here c, but the volume name has to be determined.

Is it possible to do something like this with an RegExp?

I could split the string according to the actual filename etex.src, but is the other approach possible?

Update:

The RegExp as follows

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

meets my requirements even better. How to disassemble a string with CaptureGroup?

CarpeDiemKopi
  • 316
  • 3
  • 13

2 Answers2

1

I'm guessing that maybe this expression would be somewhat close to what you might want to design:

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

DEMO

Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    Thank you Emma Peel! To search over multiple lines I had to change the dot against [^] e.g. `c:\/[^]*?(?=c:\/|$)`. Integrated in node.js with `var paths = filename.match(/c:\/[^]*?(?=c:\/|$)/g)`. – CarpeDiemKopi Jul 25 '19 at 16:06
1

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:

// 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)

GProst
  • 9,229
  • 3
  • 25
  • 47