• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Boost string_algo library example file  ---------------------------------//
2 
3 //  Copyright Pavol Droba 2002-2003. Use, modification and
4 //  distribution is subject to the Boost Software License, Version
5 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 
8 //  See http://www.boost.org for updates, documentation, and revision history.
9 
10 #include <string>
11 #include <iostream>
12 #include <iterator>
13 #include <boost/regex.hpp>
14 #include <boost/algorithm/string/regex.hpp>
15 
16 using namespace std;
17 using namespace boost;
18 
main()19 int main()
20 {
21     cout << "* Regex Example *" << endl << endl;
22 
23     string str1("abc__(456)__123__(123)__cde");
24 
25     // Replace all substrings matching (digit+)
26     cout <<
27         "replace all (digit+) in str1 with #digit+# :" <<
28         replace_all_regex_copy( str1, regex("\\(([0-9]+)\\)"), string("#$1#") ) << endl;
29 
30     // Erase all substrings matching (digit+)
31     cout <<
32         "remove all sequences of letters from str1 :" <<
33         erase_all_regex_copy( str1, regex("[[:alpha:]]+") ) << endl;
34 
35     // in-place regex transformation
36     replace_all_regex( str1, regex("_(\\([^\\)]*\\))_"), string("-$1-") );
37     cout << "transformad str1: " << str1 << endl;
38 
39     cout << endl;
40 
41     return 0;
42 }
43