• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

Regex string replace

Hi Experts,
I would like to have a function like this in Visual C++ 6.0 in MFC
RegexReplace(REGULAR_EXPRESSION, SOURCE, DESTINATION)

I downloaded the boost Regex++ library but it doesn't look like they have an API for replace... Why wouldn't they? (is it because the replace is very often ambiguous)?

Thanks for your help with this!
Best,
Mike
0
thready
Asked:
thready
  • 3
  • 2
1 Solution
 
drichardsCommented:
0
 
threadyAuthor Commented:
Yes - but how can I use this from Visual C++ 6.0?
0
 
drichardsCommented:
Build the regex library according to the directions at "<boost>/libs/regex/index.html".  See build instructions for VC6.

Then write a program like:

// VC6Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
#include <boost/regex.hpp>

int main(int argc, char* argv[])
{
      printf("Hello World!\n");
      std::string s1 = "This is string number one.";
      std::string s2 = "NUMBER";
      boost::regex rx("number");
      s1 = boost::regex_replace(s1, rx, s2);
      std::cout << s1.c_str();
      return 0;
}


which will output "This string is NUMBER one."

There is also another form of regex_replace that is fancier.
0
 
drichardsCommented:
It's not too hard.  I downloaded/built/wrote/ran in about 15 minutes.
0
 
threadyAuthor Commented:
Many thanks drichards!  
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now