[C++] Boost::Regex beginner question

salutations, I'm a complete beginner in Regex++; I've downloaded it and installed it in Visual C++ 6.0, and it's functioning properly. the problem is that I searched all over the internet and I only discovered how to do basic matching operations and basic replacing. my doubt is the following: I want to know how to do search and replace regexp operations, like it can be done in Perl by using groups (expressions surrounded by parentheses), which allow to select the substrings, matched by the regexp, in the form of $1, $2, and so on. basically, the parentheses mark the matched expression for future reference (for example, for use in the replace operation). for example (Perl example): s/X(.*?)Y/XY$1/g; I'm not sure if this explanation of what I want is very clear. I would appreciate a straightforward example code. thank you in advance. -- View this message in context: http://www.nabble.com/-C%2B%2B--Boost%3A%3ARegex-beginner-question-tp2108174... Sent from the Boost - Users mailing list archive at Nabble.com.

thank you for the response. unfortunately, we've tried to use the
regex_replace function, but it gave an unexpected error:
'regex_replace' : undeclared identifier
we used it in the following way:
#include
Let's say you had an input form that was similar to that of Boost.Format except that you could specify type information by appending a '|' followed by the type, e.g. "%1|int%", and you could name the inserts as well as use numbers (e.g., "%count|int%"). After some preprocessing to pull out the types, you then wanted to strip the type specifiers to make the string Boost.Format compliant. So '%1|int%" would become "%1%" and "%2%" would remain unchanged (because type specifiers are not required).
// This matches the insert strings, e.g. "%1|int%" with subexpressions for the number or name boost::regex const RXP_INSERT( "%(?:(\\d+)|([_a-z][_a-z0-9]*))(?:[|]([_a-z][_:a-z0-9]*))?%" , boost::regex_constants::icase); // ... // Time to strip the type specifiers. We match each insert then replace with the first two groups, // exactly one of which will be set ($1 if a number, $2 if name) msgText = boost::regex_replace(msgText, RXP_INSERT, "%$1$2%"); // No more type specifiers. Changing names to numbers is a bit more complex but this should illustrate // the principle.
At 04:41 PM 12/18/2008, P.C. wrote:
my doubt is the following: I want to know how to do search and replace regexp operations, like it can be done in Perl by using groups (expressions surrounded by parentheses), which allow to select the substrings, matched by the regexp, in the form of $1, $2
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

P.C. wrote:
NOTE: the Regex++ we are using was downloaded from the original author's site, not entirely with the Boost library. we can't understand this error. if we downloaded and installed it according to the installation instructions for VC++, how can a function be missing?
That's your problem right there: in fact I no longer have a version for download on my web pages (www.johnmaddock.co.uk), but there is an old compuserve web site of mine that keeps getting resurrected that contains a *very* old pre-boost version of the library. Unfortunately I no longer have an account or any means of removing that old web site :-( Please be sure to use the latest Boost version as it contains quite a number of bug fixes, as well as the function you're looking for, Regards, John Maddock.

2008/12/20 John Maddock
P.C. wrote:
NOTE: the Regex++ we are using was downloaded from the original author's site, not entirely with the Boost library. we can't understand this error. if we downloaded and installed it according to the installation instructions for VC++, how can a function be missing?
That's your problem right there: in fact I no longer have a version for download on my web pages (www.johnmaddock.co.uk), but there is an old compuserve web site of mine that keeps getting resurrected that contains a *very* old pre-boost version of the library. Unfortunately I no longer have an account or any means of removing that old web site :-(
Please be sure to use the latest Boost version as it contains quite a number of bug fixes, as well as the function you're looking for,
Regards, John Maddock. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
salutations, 1) I am not sure if the version we downloaded is the pre-boost one, because the site I downloaded it from makes reference to the boost library. I downloaded it from a tutorial: http://www.codeproject.com/KB/string/regex__.aspx and followed this tutorial's steps for installation. 2) how can I download only boost::regex? is it necessary to download the entire boost library? does it work with VC++ 6.0? can I use the same installation steps of that tutorial? thank you in advance.

On Sat, Dec 20, 2008 at 3:28 AM, P. C.
2008/12/20 John Maddock
: P.C. wrote:
NOTE: the Regex++ we are using was downloaded from the original author's site, not entirely with the Boost library. we can't understand this error. if we downloaded and installed it according to the installation instructions for VC++, how can a function be missing?
That's your problem right there: in fact I no longer have a version for download on my web pages (www.johnmaddock.co.uk), but there is an old compuserve web site of mine that keeps getting resurrected that contains a *very* old pre-boost version of the library. Unfortunately I no longer have an account or any means of removing that old web site :-(
Please be sure to use the latest Boost version as it contains quite a number of bug fixes, as well as the function you're looking for,
Regards, John Maddock. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
salutations,
1) I am not sure if the version we downloaded is the pre-boost one, because the site I downloaded it from makes reference to the boost library. I downloaded it from a tutorial: http://www.codeproject.com/KB/string/regex__.aspx and followed this tutorial's steps for installation. 2) how can I download only boost::regex? is it necessary to download the entire boost library? does it work with VC++ 6.0? can I use the same installation steps of that tutorial?
You can download all of boost, but build just regex with --with-regex on the bjam build line I think (can someone confirm?).
participants (4)
-
Alan M. Carroll
-
John Maddock
-
OvermindDL1
-
P.C.