부스트 regex_match를 사용하고 있으며 탭 문자가 일치하지 않는 문제가 있습니다. 나는이 인수를 사용하여 프로그램을 실행하면부스트 정규 표현식이 탭과 일치하지 않습니다.
#include <iostream>
#include <string>
#include <boost/spirit/include/classic_regex.hpp>
int
main(int args, char** argv)
{
boost::match_results<std::string::const_iterator> what;
if(args == 3) {
std::string text(argv[1]);
boost::regex expression(argv[2]);
std::cout << "Text : " << text << std::endl;
std::cout << "Regex: " << expression << std::endl;
if(boost::regex_match(text, what, expression, boost::match_default) != 0) {
int i = 0;
std::cout << text;
if(what[0].matched)
std::cout << " matches with regex pattern!" << std::endl;
else
std::cout << " does not match with regex pattern!" << std::endl;
for(boost::match_results<std::string::const_iterator>::const_iterator it=what.begin(); it!=what.end(); ++it) {
std::cout << "[" << (i++) << "] " << it->str() << std::endl;
}
} else {
std::cout << "Expression does not match!" << std::endl;
}
} else {
std::cout << "Usage: $> ./boost-regex <text> <regex>" << std::endl;
}
return 0;
}
, 내가 예상 결과를 얻을하지 않습니다 : 다음과 같이 내 테스트 응용 프로그램을 보이는이 경우
$> ./boost-regex "`cat file`" "(?=.*[^\t]).*"
Text : This text includes some tabulators
Regex: (?=.*[^\t]).*
This text includes some tabulators matches with regex pattern!
[0] This text includes some tabulators
내가 것으로 예상했을 것이다 무엇 [0] .match은 거짓이지만 그렇지 않습니다.
정규 표현식에 실수가 있습니까?
다른 형식/일치 플래그를 사용해야합니까?
미리 감사드립니다.
출력에 표시되는 것처럼 실제 프로그램에주는 텍스트에는 탭이 없습니다 (실제 탭을 인쇄하는 대신 "\ t"텍스트가 표시됨). –
이것이 맞습니다. 저는 간단한 예를 보여주고 싶었습니다! 탭 (hexdump -> 0x09로 검증 됨)을 포함한 텍스트 파일을 사용하고 있습니다. 나는 나의 모범을 교정했다! – janr