
Hi everyone! I'm Richard from romania, and I'm pretty new to boost. I started using it because I need regex functionalities. Is there a regex_search functionality that will show me all found entries for the given regular expression? Something like preg_match_all in PHP? For example, if i have a regex ([0-9]+?[\W]+?) and the search string "abcd123.ef56[tab]essn" it would return me 2 arrays of arrays: first with an array 123 and ., second with 56 and tab. Thanks. -- View this message in context: http://www.nabble.com/regex_search-all-tf4285608.html#a12199378 Sent from the Boost - Users mailing list archive at Nabble.com.

izua wrote:
Hi everyone! I'm Richard from romania, and I'm pretty new to boost. I started using it because I need regex functionalities.
Is there a regex_search functionality that will show me all found entries for the given regular expression? Something like preg_match_all in PHP? For example, if i have a regex ([0-9]+?[\W]+?) and the search string "abcd123.ef56[tab]essn" it would return me 2 arrays of arrays: first with an array 123 and ., second with 56 and tab.
You can use regex_iterator to iterate through each of the matches. John.

Hi, Is there an option to regex_search() to limit the string it searches to a certain number of non-NULL characters? Although it is possible to make a copy and null-terminate, we would like to avoid that copy. Thanks, -venkat

Venkat Rangan wrote:
Hi,
Is there an option to regex_search() to limit the string it searches to a certain number of non-NULL characters? Although it is possible to make a copy and null-terminate, we would like to avoid that copy.
Yes, don't pass a single const char*, but a pair of iterators: a pair of const char*'s will do just fine if that's the data type you have to hand - the first will point to the start of the string, the second to the point where you want searching to stop. HTH, John.

John, Thanks very much - this is almost what we want. We did notice that if there is a null before the end, the search does not stop. Any way to overcome that? We wouldn't mind doing a strlen(), but that is prone to failure, so something like strlen_s() or a safe strlen would help. But strlen_s() is not available in Microsoft MSDN 7.1. Thanks again, -venkat -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Maddock Sent: Friday, August 17, 2007 11:12 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] regex_search on non-NULL terminated strings. Venkat Rangan wrote:
Hi,
Is there an option to regex_search() to limit the string it searches to a certain number of non-NULL characters? Although it is possible to make a copy and null-terminate, we would like to avoid that copy.
Yes, don't pass a single const char*, but a pair of iterators: a pair of const char*'s will do just fine if that's the data type you have to hand - the first will point to the start of the string, the second to the point where you want searching to stop. HTH, John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Venkat Rangan wrote:
John,
Thanks very much - this is almost what we want. We did notice that if there is a null before the end, the search does not stop. Any way to overcome that? We wouldn't mind doing a strlen(), but that is prone to failure, so something like strlen_s() or a safe strlen would help. But strlen_s() is not available in Microsoft MSDN 7.1.
Ah, so you want the search to terminate if *either*: * There is a NULL character * We hit a certain length Is that right? I must admit to being a tad confused here: how do you know how long the string is (when it's created for example?) Surely you must have a length stored somewhere? John.

John, Thanks for following up. We know the size of the buffer we allocated. A workaround is to insert a NULL character at the end of the buffer, but given that these messages are created elsewhere in other components and are delivered to our search module, we do not have an opportunity to insert NULL character, forcing a copy to separate buffer under our control. The ideal interface would be: 1) terminate when NULL character is found 2) if NULL character not found, terminate when end marker is reached. -venkat -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Maddock Sent: Saturday, August 18, 2007 2:12 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] regex_search on non-NULL terminated strings. Venkat Rangan wrote:
John,
Thanks very much - this is almost what we want. We did notice that if there is a null before the end, the search does not stop. Any way to overcome that? We wouldn't mind doing a strlen(), but that is prone to failure, so something like strlen_s() or a safe strlen would help. But strlen_s() is not available in Microsoft MSDN 7.1.
Ah, so you want the search to terminate if *either*: * There is a NULL character * We hit a certain length Is that right? I must admit to being a tad confused here: how do you know how long the string is (when it's created for example?) Surely you must have a length stored somewhere? John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Venkat Rangan wrote:
John,
Thanks for following up. We know the size of the buffer we allocated. A workaround is to insert a NULL character at the end of the buffer, but given that these messages are created elsewhere in other components and are delivered to our search module, we do not have an opportunity to insert NULL character, forcing a copy to separate buffer under our control.
The ideal interface would be: 1) terminate when NULL character is found 2) if NULL character not found, terminate when end marker is reached.
I'm still somewhat confused how can use the string at all (leaving aside regex for now), if you don't know how long it is, or whether there is a terminating NULL or not. But I assume that either the buffer is full (no NULL) or not full (there is a NULL), if you know from an error code or something whether the buffer is full, then the string length is either: * The size of the buffer if the error was raised, or: * strlen(buffer) if no error was raised. Failing that you would need a "safe strlen" as you already mentioned: int strlen_s(const char* p, int len) { for(int r = 0; r < len; ++r) { if(p[r] == 0) return r; } return len; } Or you could create your own iterator type that equals the end-of-sequence iterator when either a NULL character or an end of buffer is found, but to be honest it would probably be quicker to calculate the length first as above. HTH, John.
participants (3)
-
izua
-
John Maddock
-
Venkat Rangan