당신은 이름을 캡처 그룹을 보존 할 수는 없지만, 당신은 자세한 방법으로 패턴을 정의하는 문자 여러 줄 문자열을 사용할 수 있습니다
std::string pat = "^\\s*" // optional whitespace at the start, then
"([-+]?)" // an optional sign, then
"(?=\\.?\\d)" // lookahead for digit or .digit
"(\\d*)" // numerator (possibly empty)
"(?:" // followed by
"(?:/(\\d+))?" // an optional denominator
"|" // or
"(?:\\.(\\d*))?" // an optional fractional part
"(?:E([-+]?\\d+))?" // and optional exponent
")"
"\\s*$"; // and optional whitespace to finish
std::regex e(pat);
std::string s(" -23/34 ");
std::smatch a;
if (std::regex_search(s, a, e))
std::cout << a[0] << endl;
는 C++ demo
당신이 바위를 참조하십시오. 정보는 여기서 사용하는 정규식 스타일은 무엇입니까? posix? –
아니요, ECMAScript 5입니다. POSIX는 미리보기를 지원하지 않으며 여기에'(? = \\.? \\ d)'가 있습니다. –