Search code examples
regexcmakecmake-language

How to use Cmake string regex replace to get last part of path url from multiple instances of path urls and replace the whole path with it


So my string is as follows:

TESTA:C:/Users/mycode/dir_a/./result_a/out_stra.bin;C:/Users/mycode/dir_b/./result_b/out_strb.bin;C:/Users/mycode/dir_c/./result_c/out_strc.bin
TESTB:C:/Users/mycode/dir_a/./result_a/out_stra.bin;C:/Users/mycode/dir_b/./result_b/out_strb.bin;C:/Users/mycode/dir_c/./result_c/out_strc.bin
TESTC:C:/Users/mycode/dir_a/./result_a/out_stra.bin;C:/Users/mycode/dir_b/./result_b/out_strb.bin;C:/Users/mycode/dir_c/./result_c/out_strc.bin

My required output is:

TESTA:out_stra.bin;out_strb.bin;out_strc.bin
TESTB:out_stra.bin;out_strb.bin;out_strc.bin
TESTC:out_stra.bin;out_strb.bin;out_strc.bin

I tried with string regex but I'm not getting the required output. Here is what I tried:

string(REGEX REPLACE "C:/Users/mycode/.*/\./.*/"
       "" TEMP
       <inputfilecontent>) 

will be grateful for any help. Thanks.


Solution

  • Thanks for all you answers guys, I was able to find the final solution, had to do something before adding @WiktorStribiżew solution. I had to do

    string(REGEX REPLACE ";" "\\\\;" output "${input}")
    

    to make the solution work with ";"