2010-03-14 1 views
1

pcrecpp에서 Perl의 PREMATCH ($`) 및 POSTMATCH ($ ')에 해당하는 C++ 코드를 얻을 수있는 방법이 있습니까? 나는 문자열, char *, 또는 쌍 인덱스/startpos + 길이가 만족 스러울 것이다.

StringPiece는이 부분을 달성 한 것 같지만 어떻게 가져올 지 확신하지 못합니다. 나는 같은 것 C에서

$_ = "Hello world"; 
if (/lo\s/) { 
    $pre = $`; #should be "Hel" 
    $post = $'; #should be "world" 
} 

++ : 펄

string mystr = "Hello world"; //do I need to map this in a StringPiece? 
if (pcrecpp::RE("lo\s").PartialMatch(mystr)) { //should I use Consume or FindAndConsume? 
    //What should I do here to get pre+post matches??? 
} 

PCRE의 plainjane C는 "끝"부분을 포함하여 일치와 벡터를 반환 할 수있는 능력을 갖고있는 것 같아요 문자열의, 그래서 이론적으로 같은 pre/post 변수를 추출 할 수 있지만 그것은 많은 작업처럼 보인다. 나는 pcrecpp 인터페이스의 단순화를 좋아한다.

제안 사항? 감사!

--Eric

당신은 자신을 사전에 포착하고 게시 명시 적으로 FullMatch 대신 PartialMatch의 사용 수

답변

3

, 예를 들어,

string pre, match, post; 
RE("(.*)(lo\\s)(.*)").FullMatch("Hello world", &pre, &match, &post);