@polygenelubricants answer to this question includes a C# regex that is used to split a PascalCase string into separate words, namely:
Regex r = new Regex(
@" (?<=[A-Z])(?=[A-Z][a-z]) # UC before me, UC lc after me
| (?<=[^A-Z])(?=[A-Z]) # Not UC before me, UC after me
| (?<=[A-Za-z])(?=[^A-Za-z]) # Letter before me, non letter after me
",
RegexOptions.IgnorePatternWhitespace
);
I would like to use the same regular expression in C++. However, C++ regular expression syntax does not permit lookbehinds of the form (?<=...)
. Is it possible to make this work anyways?
EDIT: This is clearly not a duplicate. I know C++ doesn't support lookbehinds, I'm asking if the same functionality can be implemented WITHOUT THEM. For reference, here's how to do it with Boost regex, which does support lookbehinds and which I would ideally like to avoid using:
#include <iostream>
#include <boost/algorithm/string/regex.hpp>
#include <boost/regex.hpp>
int main()
{
boost::regex r(
"(?<=[A-Z])(?=[A-Z][a-z])"
"|(?<=[^A-Z])(?=[A-Z])"
"|(?<=[A-Za-z])(?=[^A-Za-z])"
);
std::vector<std::string> input {
"AutomaticTrackingSystem",
"XMLEditor",
"AnXMLAndXSLT2.0Tool"
};
for (auto const &str : input) {
std::vector<std::string> str_split;
boost::algorithm::split_regex(str_split, str, r);
for (auto const &str_ : str_split)
std::cout << str_ << std::endl;
}
}