결과를 std::string
대신 re2::StringPiece
에 저장하십시오. .data()
값은 원래 문자열을 가리 킵니다.
이 프로그램을 고려하십시오. 각 테스트에서 result.data()
은 원래 const char*
또는 std::string
에 대한 포인터입니다.
#include <re2/re2.h>
#include <iostream>
int main(void) {
{ // Try it once with character pointers
const char *text[] = { "Once", "in", "Persia", "reigned", "a", "king" };
for(int i = 0; i < 6; i++) {
re2::StringPiece result;
if(RE2::PartialMatch(text[i], "([aeiou])", &result))
std::cout << "First lower-case vowel at " << result.data() - text[i] << "\n";
else
std::cout << "No lower-case vowel\n";
}
}
{ // Try it once with std::string
std::string text[] = { "While", "I", "pondered,", "weak", "and", "weary" };
for(int i = 0; i < 6; i++) {
re2::StringPiece result;
if(RE2::PartialMatch(text[i], "([aeiou])", &result))
std::cout << "First lower-case vowel at " << result.data() - text[i].data() << "\n";
else
std::cout << "No lower-case vowel\n";
}
}
}
내가 필요한 것. 감사. 설명서에 있었습니까? 나는 그것을 찾지 못할 것이다. – vy32
명시 적으로 나열된 답변을 찾지 못했지만 http://code.google.com/p/re2/source/browse/re2/re2.h#290에서 추측 할 수있었습니다. –
캡처 괄호를 추가하기 위해 정규식을 수정할 수 없다는 점을 제외하고는 똑같이해야합니다. 이 경우 부분 일치의 위치를 어떻게 알 수 있습니까? – Pavel