【发布时间】:2019-02-22 07:53:37
【问题描述】:
我正在尝试以这种方式扩展 CamelCase 字符串:CamelCase >> Camel Case,使用 boost。
string Utils::ExpandCamelCase(string & str)
{
static boost::regex camelCaseExpandRegex = boost::regex(R"(\B[A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))");
string result = boost::regex_replace(str, camelCaseExpandRegex, " $1");
return result;
}
如您所见,我正在尝试捕获第一组,它应该是每个单词的大写字母(不包括第一个),并将其替换为空格加上该组。
出现问题,因为“ExpandCamelCasePlease”变成了“Expand amel ase lease”。
尝试变体我怀疑我没有按我应该的方式捕获该组。
我需要进行哪些更改才能正确扩展大写字母前的驼峰式大小写插入空格?
【问题讨论】: