boost::regex partial matches
Hello, I apologise in advance if this question is not direct to the right mailinglist, but this was the best I could find. The IRC channel also seems very quite... :) I am currently experimenting with the boost::regex library, and so far it seems to do just the thing I need. However, when I have a regex "[0-9]+[a-zA-Z]+" And want to match this against the string "42foo 42bar" It returns false. This is (as far as I can see) due to the library not taking partial matches too, even when I set the boost::match_partial and boost::match_any flags (which, according to my interpretation, should be doing the trick). Here is my statement: bool success = boost::regex_match(subject->c_str(), returns, expression, boost::match_partial | boost::match_any); I hope anyone has an idea what might be the problem here. Thanks in advance! :) Grt, Leon Mergen
Why not use regex_search? ---------------------------------- Peace and love, Tweety mitea@sympatico.ca - tweety_04_01@users.sourceforge.net YahooID: tweety_04_01
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of L.P. Mergen Sent: Monday, November 01, 2004 10:10 AM To: boost-users@lists.boost.org Subject: [Boost-users] boost::regex partial matches
Hello,
I apologise in advance if this question is not direct to the right mailinglist, but this was the best I could find. The IRC channel also seems very quite... :)
I am currently experimenting with the boost::regex library, and so far it seems to do just the thing I need. However, when I have a regex
"[0-9]+[a-zA-Z]+"
And want to match this against the string
"42foo 42bar"
It returns false. This is (as far as I can see) due to the library not taking partial matches too, even when I set the boost::match_partial and boost::match_any flags (which, according to my interpretation, should be doing the trick).
Here is my statement:
bool success = boost::regex_match(subject->c_str(), returns, expression, boost::match_partial | boost::match_any);
I hope anyone has an idea what might be the problem here. Thanks in advance! :)
Grt,
Leon Mergen _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ahh, that did the trick, thanks a lot! Grt, Leon Mergen On Mon, 1 Nov 2004, tweety wrote:
Why not use regex_search?
---------------------------------- Peace and love, Tweety mitea@sympatico.ca - tweety_04_01@users.sourceforge.net YahooID: tweety_04_01
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of L.P. Mergen Sent: Monday, November 01, 2004 10:10 AM To: boost-users@lists.boost.org Subject: [Boost-users] boost::regex partial matches
Hello,
I apologise in advance if this question is not direct to the right mailinglist, but this was the best I could find. The IRC channel also seems very quite... :)
I am currently experimenting with the boost::regex library, and so far it seems to do just the thing I need. However, when I have a regex
"[0-9]+[a-zA-Z]+"
And want to match this against the string
"42foo 42bar"
It returns false. This is (as far as I can see) due to the library not taking partial matches too, even when I set the boost::match_partial and boost::match_any flags (which, according to my interpretation, should be doing the trick).
Here is my statement:
bool success = boost::regex_match(subject->c_str(), returns, expression, boost::match_partial | boost::match_any);
I hope anyone has an idea what might be the problem here. Thanks in advance! :)
Grt,
Leon Mergen _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I apologise in advance if this question is not direct to the right mailinglist, but this was the best I could find. The IRC channel also seems very quite... :)
Exactly the right list.
I am currently experimenting with the boost::regex library, and so far it seems to do just the thing I need. However, when I have a regex
"[0-9]+[a-zA-Z]+"
And want to match this against the string
"42foo 42bar"
It returns false. This is (as far as I can see) due to the library not taking partial matches too, even when I set the boost::match_partial and boost::match_any flags (which, according to my interpretation, should be doing the trick).
Here is my statement:
bool success = boost::regex_match(subject->c_str(), returns, expression, boost::match_partial | boost::match_any);
You need to use regex_search, and *not* a partial match, these extracts from the docs should make this clear: regex_match: "Note that the result is true only if the expression matches the whole of the input sequence. If you want to search for an expression somewhere within the sequence then use regex_search. If you want to match a prefix of the character string then use regex_search with the flag match_continuous set.". partial matches: "A partial match is one that matched one or more characters at the end of the text input, but did not match all of the regular expression (although it may have done so had more input been available)". Hope this makes things clear. John.
Essentially, I'm passing a function a scoped_array and I want to assign data to it. It seems like there isn't a way to copy a chunk of data to the scoped_array except when it is created. Functionaly I'm where I want to be, but I'm thinking I must be misunderstanding the correct way to do this. I'm getting the data from a DLL that allocates its own memory, so I have to copy the data locally, then call the DLL's function to release the memory. Is this the best way to accomplish what I'm after? Thanks, Adam This is currently how I'm doing it: function blah(...., scoped_array<APPRIGHTITEM>& saGroups ) { LPAPPRIGHTITEM lpAppRightItemList = NULL; get_my_data( &lpAppRightItemList, &dwCount ); LPAPPRIGHTITEM sap = (LPAPPRIGHTITEM) new APPRIGHTITEM [ dwRightCount ]; memcpy(sap, lpAppRightItemList, sizeof(APPRIGHTITEM) * dwRightCount); scoped_array<APPRIGHTITEM> saTemp ( sap ); saGroups.swap( saTemp ); FreeList( lpAppRightItemList ); }
Adam Peterson wrote:
Essentially, I'm passing a function a scoped_array and I want to assign data to it. It seems like there isn't a way to copy a chunk of data to the scoped_array except when it is created. Functionaly I'm where I want to be, but I'm thinking I must be misunderstanding the correct way to do this. I'm getting the data from a DLL that allocates its own memory, so I have to copy the data locally, then call the DLL's function to release the memory. Is this the best way to accomplish what I'm after?
It seems to me that you've missed scoped_array::reset:
scoped_array<APPRIGHTITEM> saTemp ( sap ); saGroups.swap( saTemp );
is exactly what saGroups.reset( sap ) would do. You could also return a shared_array to avoid the local copy: shared_array<APPRIGHTITEM> blah( ... ) { LPAPPRIGHTITEM lp = NULL; DWORD dw = 0; get_my_data( &lp, &dw ); if( lp ) { return shared_array<APPRIGHTITEM>( lp, FreeList ); } else { return shared_array<APPRIGHTITEM>(); } } Depending on how get_my_data and FreeList are specified, you may not need the if. This approach also makes the code exception-safe; the original seems to leak the list when new throws. And of course if you needed the item count, you would've returned a std::vector. :-)
participants (5)
-
Adam Peterson
-
John Maddock
-
L.P. Mergen
-
Peter Dimov
-
tweety