Search code examples
javascriptnode.jsregexwindowstex

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

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?


Solution

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

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

    DEMO