Advertisement
obernardovieira

[Boost] regex and inverse regex

Mar 14th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <boost/regex.hpp>
  2. #include <iostream>
  3. #include <string>
  4. int main()
  5. {
  6.     std::string text("dgdr<text>55,99.5,99.6</text>svf<text>55,99.5,99.6</text>frdg");
  7.     const char* pattern = "<text>(.*?)</text>";
  8.  
  9.     boost::sregex_iterator it(text.begin(), text.end(), boost::regex(pattern));
  10.     boost::sregex_iterator end;
  11.     for (; it != end; ++it) {
  12.         std::string novotexto(it->str());
  13.         //get inverse regex
  14.         boost::sregex_token_iterator p(novotexto.begin(), novotexto.end(), boost::regex("<(.|\n)*?>"), -1);
  15.         boost::sregex_token_iterator den;
  16.  
  17.         for (;p != den; ++p)
  18.         {
  19.             std::string m(p->first, p->second);
  20.             std::cout << m << std::endl;
  21.  
  22.             boost::sregex_iterator sp(m.begin(), m.end(), boost::regex("[^,]+"));
  23.             boost::sregex_iterator fim;
  24.                        
  25.             for (; sp != fim; ++sp) {
  26.                 std::cout << sp->str() << std::endl;
  27.             }
  28.  
  29.         }
  30.  
  31.     }
  32.     std::cin.get();
  33.     return 1;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement