Regex translation

I have used regular expressions in Perl, but not C++. After I read in a Web Page I want to re-format it’s spacing and new lines. The first step is to remove all the old spacing. This is the code I used in Perl:

1
2
3
4
5
6
7
8
9
10
11
# get rid of all non-ASCII characters
$webPage =~ s/[^[:ascii:]]+//g;  
# Get rid of line breaks in raw webPage
$webPage =~ s/\r//g;
$webPage =~ s/\n//g;
$webPage =~ s/\t/ /g;
# Change multiple spaces to single spaces in raw webPage
for ( my $count = 25 ;  $count > 0 ; $count--)	
{
    $webPage =~ s/  / /g;
}

What would the equivalent coding be for C++?

The =~ regex string replacement operator doesn’t seem to be there in C++!
See std::regex_replace: http://www.cplusplus.com/reference/regex/regex_replace/

BTW, $webpage =~ s/ +/ /g; can be used in place of the for loop above.
Topic archived. No new replies allowed.