부스트 xpressive sregex 할당에 이상한 동작이 있습니다. 아래 코드를 참조하십시오. 작동하지 않는 첫 번째 코드 조각은 sregex에 객체 예비 할당이 있고 나중에 주 표현식에서 사용됩니다. 잘 작동하는 두 번째 코드 스 니펫에는 이전 sregex 할당이 없습니다 (최종 주된 예외는 제외). 부스트 Xpressive API를 잘못 사용하고 있다면 알려주십시오.부스트 Xpressive sregex 할당 및 캡쳐 그룹 문제
mark_tag Value1(1), Value2(2), Value3(3), Value4(4), Value5(5), Value6(6), Value7(7);
boost::xpressive::sregex name,multicast,rtsp;
name = ((Value1 = (+boost::xpressive::set[_w|_d|'-'|'_'|as_xpr(' ')])) >> ',');
name1 =
((Value2 = icase(as_xpr("mark1:")))
>> (Value3 = (+boost::xpressive::set[_d|'.']))
>> ':'
>> (Value4 = (+boost::xpressive::set[_d])) >> optional(as_xpr(",")));
name2 =
((Value5 = icase(as_xpr("mark2:")))
>> (Value6 = (+boost::xpressive::set[_d|'.']))
>> ':'
>> (Value7 = (+boost::xpressive::set[_d])) >> optional(as_xpr(","))) ;
boost::xpressive::sregex pt = bos
>> (
name
>> repeat<0,2>(
name1
|
name2)
)
>> eos;
boost::trim(string_to_parse);
smatch what;
if (!regex_search(string_to_parse, what, pt)) {
std::stringstream ss;
ss << "Unable to parse: " << string_to_parse;
throw parse::MyException(ss.str());
}
std::string Value1_str = what[Value1]; // print them later
std::string Value2_str = what[Value2]; // print them later
std::string Value3_str = what[Value3]; // print them later
std::string Value4_str = what[Value4]; // print them later
std::string Value5_str = what[Value5]; // print them later
std::string Value6_str = what[Value6]; // print them later
std::string Value7_str = what[Value7]; // print them later
string_to_parse = NameX,mark1:192.168.1.100:5555,mark2:192.168.1.101:5556;
작동하지 않습니다
코드 [<은>] 값을 포함하지 않는 것을 의미 (구문 분석 실패).
string_to_parse = NameX,mark1:192.168.1.100:5555,mark2:192.168.1.101:5556;
mark_tag Value1(1), Value2(2), Value3(3), Value4(4), Value5(5), Value6(6), Value7(7);
sregex pt = bos
>> (
((Value1 = (+boost::xpressive::set[_w|_d|'-'|'_'|as_xpr(' ')])) >> ',')
>> repeat<0,2>(
((Value2 = icase(as_xpr("mark1:"))) >> (Value3 = (+boost::xpressive::set[_d|'.'])) >> ':' >> (Value4 = (+boost::xpressive::set[_d])) >> optional(as_xpr(",")))
|
((Value5 = icase(as_xpr("mark2:"))) >> (Value6 = (+boost::xpressive::set[_d|'.'])) >> ':' >> (Value7 = (+boost::xpressive::set[_d])) >> optional(as_xpr(","))))
)
>> eos;
boost::trim(string_to_parse);
smatch what;
if (!regex_search(string_to_parse, what, pt)) {
std::stringstream ss;
ss << "Unable to parse: " << string_to_parse;
throw parse::MyException(ss.str());
}
std::string Value1_str = what[Value1]; // print them later
std::string Value2_str = what[Value2]; // print them later
std::string Value3_str = what[Value3]; // print them later
std::string Value4_str = what[Value4]; // print them later
std::string Value5_str = what[Value5]; // print them later
std::string Value6_str = what[Value6]; // print them later
std::string Value7_str = what[Value7]; // print them later
작동 코드는 중첩 된 정규 표현식에있는 패턴과 일치하는 경우
"저자는 내부 정규 표현식이 하위 일치 벡터를 밟을 지 여부를 알 수있는 방법이 없습니다." 그래서 해결책은 무엇입니까? regex_match() 또는 regex_search()를 사용하면 match_results <> ??? – enthusiasticgeek
문서 읽기! 모든 것이 있습니다. regex_match 또는 regex_search를 사용하든 관계없이 모든 역 참조가 저장되지만,이 경우 match_results :: nested_results가 반환하는 컬렉션에 있어야합니다. 하지만 진지하게. 문서를 읽으십시오. –