What can I use for conditional replacements for regular expression objects in regex python just like this javascript code?
var string = "heLlo, woRlD!";
string = string.replace( /([a-zA-Z])([a-zA-Z]+)/g, function(match, g1,
g2) {
return g1.toUpperCase() + g2.toLowerCase();
});
console.log( string ); // "Hello, World!"
I want to replace every pattern matches in the sentences. In regex pattern, there are two conditions and if we output re.groups, there are 2 groups and I want to perform another regex operation and then replace these new transformed groups with the matched parts in original sentence. It's operation is the same as this javascript code describes but only the operation to groups is different. Do you have any recommendation?