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
clojure
(.replaceAll (re-matcher #"se\w+" "She sells sea shells") "X")
ExpandDiskEdit
fsharp
let replaced = ((new Regex("se\\w+")).Replace("She sells sea shells", "X"))
printfn "%s" replaced
ExpandDiskEdit
fantom
replaced := Regex<|se\w+|>.split("She sells sea shells").join("X")
ExpandDiskEdit
java
String replaced = text.replaceAll("se\\w+", "X");
ExpandDiskEdit
cpp C++/CLI .NET 2.0
String^ Replaced = (gcnew Regex("se\\w+"))->Replace("She sells sea shells", "X");
ExpandDiskEdit
cpp C++/CLI .NET 2.0
String^ Replaced = Regex::Replace("She sells sea shells", "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}]).

Submit a new solution for python, clojure, fsharp, fantom ...
There are 7 other solutions in additional languages (csharp, groovy, ocaml, perl ...)