
I am compiling the program using the following option g++ -ggdb -lboost_regex -o regex regex.cpp but it is giving error. #include <boost/regex.hpp> #include <iostream> void print_captures(const std::string& regx, const std::string& text) { boost::regex e(regx); boost::smatch what; std::cout << "Expression: \"" << regx << "\"\n"; std::cout << "Text: \"" << text << "\"\n"; if(boost::regex_match(text, what, e, boost::match_extra)) { unsigned i, j; std::cout << "** Match found **\n Sub-Expressions:\n"; for(i = 0; i < what.size(); ++i) std::cout << " $" << i << " = \"" << what[i] << "\"\n"; std::cout << " Captures:\n"; for(i = 0; i < what.size(); ++i) { std::cout << " $" << i << " = {"; for(j = 0; j < what.captures(i).size(); ++j) { if(j) std::cout << ", "; else std::cout << " "; std::cout << "\"" << what.captures(i)[j] << "\""; } std::cout << " }\n"; } } else { std::cout << "** No Match found **\n"; } } int main(int , char* []) { print_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee"); print_captures("(.*)bar|(.*)bah", "abcbar"); print_captures("(.*)bar|(.*)bah", "abcbah"); print_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party"); return 0; } Error message: regex.cpp: In function ‘void print_captures(const std::string&, const std::string&)’: regex.cpp:20: error: ‘class boost::smatch’ has no member named ‘captures’ regex.cpp:26: error: ‘class boost::smatch’ has no member named ‘captures’ How can i avoid that. Please help me. -- View this message in context: http://www.nabble.com/How-to-compile-boost-regex-tp25447212p25447212.html Sent from the Boost - Users mailing list archive at Nabble.com.

AMDG manish4gupta wrote:
I am compiling the program using the following option g++ -ggdb -lboost_regex -o regex regex.cpp but it is giving error.
<snip> for(j = 0; j < what.captures(i).size(); ++j)
<snip>
Error message: regex.cpp: In function ‘void print_captures(const std::string&, const std::string&)’: regex.cpp:20: error: ‘class boost::smatch’ has no member named ‘captures’ regex.cpp:26: error: ‘class boost::smatch’ has no member named ‘captures’
How can i avoid that. Please help me.
There is no function called captures. Use the subscript operator. what[i].size() In Christ, Steven Watanabe

Still i am getting the following error. regex.cpp: In function ‘void print_captures(const std::string&, const std::string&)’: regex.cpp:20: error: ‘const struct boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >’ has no member named ‘size’ regex.cpp:26: error: no match for ‘operator[]’ in ‘what.boost::match_results<BidiIterator, Allocator>::operator[] [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >
](((int)i))[j]’ manish@user-desktop:~/Desktop$ g++ -ggdb -lboost_regex regex.cpp regex.cpp: In function ‘void print_captures(const std::string&, const std::string&)’: regex.cpp:20: error: ‘const struct boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >’ has no member named ‘size’ regex.cpp:26: error: no match for ‘operator[]’ in ‘what.boost::match_results<BidiIterator, Allocator>::operator[] [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > ](((int)i))[j]’
Steven Watanabe-4 wrote:
AMDG
manish4gupta wrote:
I am compiling the program using the following option g++ -ggdb -lboost_regex -o regex regex.cpp but it is giving error.
<snip> for(j = 0; j < what.captures(i).size(); ++j)
<snip>
Error message: regex.cpp: In function ‘void print_captures(const std::string&, const std::string&)’: regex.cpp:20: error: ‘class boost::smatch’ has no member named ‘captures’ regex.cpp:26: error: ‘class boost::smatch’ has no member named ‘captures’
How can i avoid that. Please help me.
There is no function called captures. Use the subscript operator. what[i].size()
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- View this message in context: http://www.nabble.com/How-to-compile-boost-regex-tp25447212p25466226.html Sent from the Boost - Users mailing list archive at Nabble.com.

I am compiling the program using the following option g++ -ggdb -lboost_regex -o regex regex.cpp but it is giving error.
As noted in the documentation, captures are only enabled when BOOST_REGEX_MATCH_EXTRA is defined both when building that specific example, and when the regex library was also built with that defined. See http://www.boost.org/doc/libs/1_40_0/libs/regex/doc/html/boost_regex/capture... HTH, John. PS Note that regular Perl-style marked sub-expressions are *always* supported regardless of BOOST_REGEX_MATCH_EXTRA being set.
participants (3)
-
John Maddock
-
manish4gupta
-
Steven Watanabe