user4016367 user4016367 - 1 year ago 106
C++ Question

c++ regex get folder from a file path

I have a file name like this


how to replace the file name with
using regex so I get


I know the simple for loop split or
approach, I'm looking for a

Answer Source

You don't need regexp for this:

string str = "/mnt/opt/storage/ssd/subtitles/8/vtt/2011022669-5126858992107.vtt";
auto lastSlash = str.find_last_of('/');
str.replace(str.begin() + lastSlash + 1, str.end(), "*");