View Problem

Replace all regex matches in a string with a static string

Transform "She sells sea shells" into "She X X shells" by replacing /se\w+/ with "X"
DiskEdit
python
transformed = re.sub(r'se\w+', 'X', 'She sells sea shells')
DiskEdit
csharp
using System.Text.RegularExpressions;

class SolutionXX
{
static void Main()
{
string text = "She sells sea shells";
string result = Regex.Replace(text, @"se\w+", "X");
}
}
ExpandDiskEdit
erlang
% Erlang uses 'egrep'-compatible regular expressions, so shortcuts like '\w' not supported
{ok, Replaced, _} = regexp:gsub("She sells sea shells", "se[A-Za-z0-9_]+", "X"),
DiskEdit
erlang 12B3+
re:replace("She sells sea shells", "se\\w+", "X", [global, {return, list}]).
DiskEdit
clojure
(.replaceAll (re-matcher #"se\w+" "She sells sea shells") "X")

Submit a new solution for python, csharp, erlang, or clojure
There are 11 other solutions in additional languages (cpp, fantom, fsharp, groovy ...)