Ticket #13516: example.cc

File example.cc, 1.3 KB (added by Aron Pongo <aron@…>, 5 years ago)
Line 
1#include <string>
2#include <boost/regex/icu.hpp>
3#include <iostream>
4
5const std::string find_exp = "(?s)(?x)(?<=<(?'maintag'italic)>)(?'main'\\((?'innertext'(?>(?|(?:(?:(?![()])(?!<(?!WRK)\\b)(?!</(?!WRK)\\b).)++(?:<(?'tagname'\\w++)[^>]*+>(?'tagbody'(?>(?:(?!<\\k'tagname'\\b)(?!</\\k'tagname'\\b).)++|<\\k'tagname'\\b[^>]*+>(?&tagbody))*+</\\k'tagname'>))?)|(?:<(?'tagname'\\w++)[^>]*+>(?'tagbody'(?>(?:(?!<\\k'tagname'\\b)(?!</\\k'tagname'\\b).)++|<\\k'tagname'\\b[^>]*+>(?&tagbody))*+</\\k'tagname'>))|(?&main)))*+)\\))(?=</\\k'maintag'>)";
6
7const std::string replace_exp = "~~$+{innertext}~~";
8
9const std::string search_in = "<para>The third and final section, <italic>(Part (III))</italic>, consists of the following appendixes</para>";
10
11int test()
12{
13 boost::u32regex expr = boost::make_u32regex(find_exp);
14 boost::u32regex_iterator<std::string::const_iterator> match(search_in.begin(), search_in.end(), expr);
15 boost::u32regex_iterator<std::string::const_iterator> end;
16 for (; match != end; ++match)
17 {
18 boost::match_results<std::string::const_iterator> result = *match;
19 std::cout << "hit" << std::endl;
20 std::string replace_str = result.format(replace_exp, boost::format_perl);
21 std::cout << replace_str << std::endl;
22 }
23
24 std::cout << "Finished!" << std::endl;
25
26 return 0;
27}
28
29int main()
30{
31 return test();
32}