boost-regex

Getting sub-match_results with boost::regex

谁说我不能喝 提交于 2019-12-10 06:28:26
问题 Hey, let's say I have this regex: (test[0-9])+ And that I match it against: test1test2test3test0 const bool ret = boost::regex_search(input, what, r); for (size_t i = 0; i < what.size(); ++i) cout << i << ':' << string(what[i]) << "\n"; Now, what[1] will be test0 (the last occurrence). Let's say that I need to get test1 , 2 and 3 as well: what should I do? Note: the real regex is extremely more complex and has to remain one overall match, so changing the example regex to (test[0-9]) won't

C++ to convert Boost Regex match result to other format [duplicate]

陌路散爱 提交于 2019-12-06 05:49:56
This question already has answers here : Closed 7 years ago . Possible Duplicate: How to convert a number to string and vice versa in C++ How should I convert the boost::regex match result to other format, like integer with below code? string s = "abc123"; boost::regex expr("(\\s+)(\\d+)"); boost::smatch match; if(boost::regex_search(s, match, expr)) { string text(match[0]); // code to convert match[1] to integer } I'm sure you'd like to have string text(match[1]); // convert match[2] to integer instead, as match[0] is the whole matched thing (abc123 here), so submatch indexing starts at 1. As

C++/Boost: Writing a more powerful sscanf replacement

女生的网名这么多〃 提交于 2019-12-05 23:31:04
问题 I want to write a function in C++ to replace C's sscanf that assigns the matches to iterator. Basically, I want something like: string s = "0.5 6 hello"; std::vector<boost::any> any_vector; sscanv(s, "%f %i %s", any_vector); cout << "float: " << any_cast<float>(any_vector[0]); cout << "integer: " << any_cast<integer(any_vector[1]); cout << "string: " << any_cast<string>(any_vector[2]); The exact details may vary, but you get the idea. Any ideas for implementation? Options so far along with

Boost.Regex vs C++11 Regex

匆匆过客 提交于 2019-12-03 23:32:34
Could someone explain the differences between the two? Which would be better to learn right now? How would knowledge transfer from one to the other and vice-versa? The boost regex library made it into C++0x so I'm guessing it will slowly be removed from boost. However, using boost is nice because you can still use it with compilers without C++0x support. So it's really up to you. One major difference is, that C++11 does not provide the Perl syntax for regular expressions. So, if you tend to use Perl syntax you have to use the Boost::Regex library. At least in Visual Studio 2013 this and

Cannot link Boost regex

烂漫一生 提交于 2019-12-03 11:18:39
I am currently trying to compile a Contraction Hierachies implementation by KIT which requires Boost::Regex. The supplied Makefile already makes sure (and I have also double-checked this manually) that g++ is supplied with the -lboost_regex switch. If the library is not installed, g++ will complain. So I installed the library from my package sources and tried compiling again. This time I am getting a huge load of linker errors regarding Boost::Regex. Here is a short excerpt: main.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std:

While doing url encoding, the std::regex_replace doesn't work properly for character “+”

大城市里の小女人 提交于 2019-12-02 04:56:12
问题 Following is the code snippet, the regex_replace dosn't work properly for character "+", I should not use special handling for the characters, but it should work properly. /*All headerfiles are available.*/ std::string charToHex(unsigned char c, bool bUpperCase); std::string urlEncode(const std::string& toEncode, bool bEncodeForwardSlash); std::string getEncodedUrl(const std::string& url){ std::string bktObjKey = ""; std::string urlEnc = url; boost::regex expression("^(([^:/?#]+):)?(//([^/?#:

While doing url encoding, the std::regex_replace doesn't work properly for character “+”

℡╲_俬逩灬. 提交于 2019-12-01 22:46:01
Following is the code snippet, the regex_replace dosn't work properly for character "+", I should not use special handling for the characters, but it should work properly. /*All headerfiles are available.*/ std::string charToHex(unsigned char c, bool bUpperCase); std::string urlEncode(const std::string& toEncode, bool bEncodeForwardSlash); std::string getEncodedUrl(const std::string& url){ std::string bktObjKey = ""; std::string urlEnc = url; boost::regex expression("^(([^:/?#]+):)?(//([^/?#:]*)(:\\d+)?)?([^?#]*)((\\?[^#]*))?(#(.*))?"); std::string::const_iterator start=url.begin(), end = url

Why does regex_match throw “complexity exception”?

[亡魂溺海] 提交于 2019-12-01 18:07:40
I am trying to test (using boost::regex ) whether a line in a file contains only numeric entries seperated by spaces. I encountered an exception which I do not understand (see below). It would be great if someone could explain why it is thrown. Maybe I am doing something stupid here in my way of defining the patterns? Here is the code: // regex_test.cpp #include <string> #include <iostream> #include <boost/regex.hpp> using namespace std; using namespace boost; int main(){ // My basic pattern to test for a single numeric expression const string numeric_value_pattern = "(?:-|\\+)?[[:d:]]+\\.?[[

How can I find the index in a string that matches a boost regex?

早过忘川 提交于 2019-12-01 11:03:00
How can I find the index in a string that matches a boost regex? If you use boost::regex_match it's the whole string that's matching. Maybe you mean to use regex_search: void index(boost::regex& re,const std::string& input){ boost::match_results<std::string::const_iterator> what; boost::match_flag_type flags = boost::match_default; std::string::const_iterator s = input.begin(); std::string::const_iterator e = input.end(); while (boost::regex_search(s,e,what,re,flags)){ std::cout << what.position() << std::endl; std::string::difference_type l = what.length(); std::string::difference_type p =

Boost Regex not playing welll with Snow leopard

偶尔善良 提交于 2019-12-01 11:01:28
So I inherited code written in C++ that uses the Boost library. I could compile (using Code Blocks) and run the code on Linux Ubuntu but when I ported it over to the mac and installed the boost library, I can compile it using code blocks (and specifying the location of the regex libraries) but it won't run. It just gives me the error: $ ./BLAH_PD dyld: Library not loaded: libboost_regex.dylib Referenced from: /Users/spinach/Desktop/B/BLAH/bin/Release/./BLAH_PD Reason: image not found Trace/BPT trap I'm not sure what to do next but any help would be greatly appreciated. David You need to set