$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Scott Meyers (usenet_at_[hidden])
Date: 2006-11-21 18:00:35
If I want to replace all the regex matches in a string, no problem, 
regex_replace is just what I'm looking for.  But suppose I want to 
replace each match only if some predicate is satisfied, e.g., to 
implement something like a string replacement in a text editor where the 
user is allowed to approve or reject each proposed replacement.  Is 
there any direct support for something like this?
The only way I can think of to do this is to iterate over the string to 
be searched, finding each match and then consulting the predicate to see 
if the replacement should be performed for that match.  If so, I can 
call regex_replace on the found substring, but then I'll get back a new 
string, and I'll have to manually handle the process of knitting 
together the final revised string from the original string and the 
results of each substitution.  This is essentially what regex_replace 
already does, except it unconditionally does a substitution for each 
match.
What it seems I want is something like regex_replace_if.  Is there such 
a thing in Boost or TR1?  If not, is it because there is little demand 
for such functionality?  That would surprise me, because pretty much 
every text editor allows one to iteratively search for a match and query 
the user to see if a replacement should be performed at that point.
Thanks,
Scott