1
내가 가지고 올 수있는 최선 : 출력C에서 정규 표현식 검색 및 바꾸기 + +?
#include <boost/algorithm/string/replace.hpp>
#include <boost/regex.hpp>
#include <iostream>
using namespace std;
int main() {
string dog = "scooby-doo";
boost::regex pattern("(\\w+)-doo");
boost::smatch groups;
if (boost::regex_match(dog, groups, pattern))
boost::replace_all(dog, string(groups[1]), "scrappy");
cout << dog << endl;
}
:
scrappy-doo
.. 두 가지 검색을 수행 포함하지 않는이 일을 간단한 방법이 있나요? 어쩌면 새로운 C++ 11 자료 (gcc atm과 호환되는지 확실하지 않지만)
있습니다. 이전 인터페이스에서 정규식 그룹을 나타 내기 위해 $ x 구문을 사용하여 새로운 문자열을 효과적으로 다시 작성해야하기 때문에이 인터페이스는 반 직관적입니다. 그 말은, 나는 더 나은 것을 생각할 수 없다. – mavix