Cant find out how to match two periods but not one.
Code:
static std::vector<std::string> splitPath(const std::string& path)
{
std::vector<std::string> components;
std::regex delimiterSplitter("[^\\\\/]+");
auto begin = std::sregex_iterator(path.begin(), path.end(), delimiterSplitter);
auto end = std::sregex_iterator();
for (auto it = begin; it != end; it++)
components.push_back((*it).str());
return components;
}
Paths like ../Resources and ../Resources/composition.json are split like expected into [..|Resources] and [..|Resources|composition.json] respectively.
But in addition, i would like to split the path so that the extension and name are separate. For example i want ../Resources/composition.json to be split into [..|Resources|composition|json].
So obviously i have to in some way differentiate between one period, and two periods, and match on the former but not latter. I've been struggling for hours and cant find out the appropriate regex for this.
Does anyone have any ideas? Im not very proficient in regex, and my soul is slowly leaving my body.
Posted Aug 19, 2019, 12:27 AM UTC
12
If it's always going to be two periods at the beginning, you can do something like this:
\.\.|[^\\\/.]+That matches
..first and then matches everything that's not a\,/, or.. It should give you the desired [..|Resources|composition|json]Here's a demo.
[deleted]