Linked Questions
15 questions linked to/from regex replace with callback in c++11?
0
votes
1
answer
471
views
its possible c++ regex evaluator with lambdas like ruby? [duplicate]
Im trying to learn how I could write a regex evaluator in c++ with lambda expression
5;4
11;2
7;3
inputx.gsub(/(.*?);(.*?)\n/) { ($1.to_i - $2.to_i ).to_s + "\n" }
1
9
4
How I could do this if ...
20
votes
2
answers
49k
views
Conditionally replace regex matches in string
I am trying to replace certain patterns in a string with different replacement patters.
Example:
string test = "test replacing \"these characters\"";
What I want to do is replace all ' ' with '_' ...
1
vote
2
answers
2k
views
Selectively replace (") doublequotes in a std::string in C++
I want to selectively replace the (") doublequotes in a C++ std::string.
i.e. i want to replace all occurences of (") doublequotes in a string except the 1st and last occurence of (") doublequotes in ...
4
votes
2
answers
2k
views
How do I use std::regex_replace to replace string into lowercase?
I find this regex for replacement Regex replace uppercase with lowercase letters
Find: (\w) Replace With: \L$1
My code
string s = "ABC";
cout << std::regex_replace(s, std::regex("(\\w)"), "\\...
0
votes
2
answers
1k
views
C++ Regex Replace One by One
Suppose my string is "g500() g600() g200()\n g1()" I want to output "g1() g2() g3()\n g4()" instead.
I have tried using regex to do it like so, but this gives each occurence the same value.
#...
2
votes
3
answers
404
views
Parse (replace) in C++ std::string
I have a "custom" string that has the following format. Example:
std::string MyString = "RndOrder%5d - RndCustomer%8s - RndHex%8x";
I would like to replace/parse the string:
the %5d (%NUM_d) would be ...
6
votes
3
answers
203
views
How to match only those numbers which have an even number of `%`s preceding them?
I want to catch numbers appearing anywhere in a string, and replace them with "(.+)".
But I want to catch only those numbers which have an even number of %s preceding them. No worries if any ...
0
votes
2
answers
523
views
How to Simplify C++ Boolean Comparisons
I'm trying to find a way to simplify the comparison cases of booleans. Currently, there are only three (as shown below), but I'm about to add a 4th option and this is getting very tedious.
...
0
votes
3
answers
558
views
Obtain iterators from std::regex_search and use these in string::replace
I am having ridiculous difficulties matching a regex and replacing the match with another string. I want to achieve this with iterators, as outlined below. The part that does not work is getting ...
2
votes
1
answer
624
views
Regex to replace all occurrences between two matches
I am using std::regex and need to do a search and replace.
The string I have is:
begin foo even spaces and maybe new line(
some text only replace foo foo bar foo, keep the rest
)
some more text not ...
0
votes
1
answer
281
views
Find $number and then replace it with $number+1?
I would like to find $number substrings and then replace them with $number + 1 format.
For example, $1 should become $2 in a string.
So far, I found out how to find $number pattern in a string and ...
0
votes
1
answer
162
views
Regex replacement capture followed by digit separation [duplicate]
I'm trying to learn using regex in C++ and I got this code:
std::string s("21\n");
std::regex e("\\b(2)1");
std::cout << std::regex_replace(s, e, "${1}0 first");
I wanna turn
21
into
...
0
votes
1
answer
283
views
Is there a C++ equivalent for Perl's \L in regex replacement strings? [duplicate]
In Perl, I can replace characters with their lowercase version like so:
my $str = "HELLO WORLD HOW ARE YOU TODAY";
$str =~ s/([AEIOU])/\L\1/g;
print $str; # HeLLo WoRLD HoW aRe You ToDaY";
How can I ...
3
votes
2
answers
107
views
Replace tag1 tag2 tag3 for x1 x2 x3
I'm very new to regex and C++, so please be easy on me :) !
Given a string like this one:
Input:
string s = "<ph0/>Hello StackOverflow! Thank you for helping! <ph1/>"
I want to replace ...
1
vote
0
answers
77
views
C++ Regex Iterator Returning Strange Results, Despite Correct Expression
I am reading/modifying an XML file line by line, and I run into some problems when trying to identify some variables.
For example, I have two lines:
I have the following regex ...