0

I want to split up an UNC-path for hostname, shared folder, path, filename and extension. I almost got it, but the last sequence is somehow wrong because I didn't get the filenaem correctly.

e.g.

//host/shared/path1/path2/path3/filename.pdf

should be split up to:

host
shared
path1/path2/path3
filename
pdf

But at the moment I get something like this:

host
shared
path1/path2/path3/filenam
e
pdf

using this regex:

std::regex rgx("\/\/(\\w+?){1,1}\/(\\w+?)\/([\\w\/]+)([^\\.])\\.(.+)$");

So what is wrong with it and how can I solve it?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
mbed_dev
  • 1,450
  • 16
  • 33

1 Answers1

2

You want to remove the group "([^\\.])" as the following "\\." matches the period at the end. You also want another word group to match the file name itself that is followed by the period like so:

std::regex rgx("\/\/(\\w+?){1,1}\/(\\w+?)\/([\\w\/]+)\/([\\w]+)\\.(.+)$");

https://regex101.com/r/yK4zH1/4

Cariboutis
  • 301
  • 1
  • 7