다음 문자열과 함께 BOOST의 wsregex :: compile을 사용하려고 할 때 내 프로그램이 충돌하는 이유를 이해하고 싶습니다.
(?P<path>\b[a-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*)?
(:)?
(?P<ip>(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)
(;(?P<port>\d*))?
(:(?P<port>\b\d+\b):(?P<password>[\w]*))?
(:(?P<password>\b\d+\b))?
정규식 친구에서는 모든 것이 정상인 것 같습니다. RegexBuddy에서 JGSoft 플레이버 옵션을 사용했습니다.
다음을 확인하고 있습니다.
c:\My Documents\Test\test.csv:1.12.12.13:111:admin
c:\My Documents\Test\test.csv:1.12.12.13:111
c:\My Documents\Test\test.csv:1.12.12.13;111
1.12.12.13:111
1.12.12.13;111
저 좀 도와 주 시겠어요? 감사합니다.
내가 말할 수있는 한 이것은 메모리 누수 나 충돌이 아닙니다. 잘못된 패턴이기 때문에 Xpressive에서 예외가 발생합니다. 다음 프로그램 :
#include <iostream>
#include <boost/xpressive/xpressive_dynamic.hpp>
namespace xpr = boost::xpressive;
int main()
{
const char pattern[] =
"(?P<path>\\b[a-z]:\\\\(?:[^\\\\/:*?\"<>|\\r\\n]+\\\\)*[^\\\\/:*?\"<>|\\r\\n]*)?"
"(:)?"
"(?P<ip>(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b)"
"(;(?P<port>\\d*))?"
"(:(?P<port>\\b\\d+\\b):(?P<password>[\\w]*))?"
"(:(?P<password>\\b\\d+\\b))?";
try
{
xpr::sregex rx = xpr::sregex::compile(pattern);
}
catch(xpr::regex_error const & e)
{
std::cout << e.what() << std::endl;
}
}
출력 :
named mark already exists
실제로 그렇습니다. 이 패턴은 캡처 그룹의 이름으로 "port"와 "password"를 두 번 사용합니다. Xpressive는 그것을 좋아하지 않습니다. 캡처에 고유 한 이름을 선택하면 괜찮을 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다