Login
|
Signup
langref.org
-
python
,
fsharp
,
fantom
,
groovy
...
add..
all
clojure
cpp
csharp
erlang
go
java
ocaml
perl
php
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Regex
Replacing
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"
python
transformed = re.sub(r'se\w+', 'X', 'She sells sea shells')
transformed = re.sub(r'se\w+', 'X', 'She sells sea shells')
fsharp
let replaced = ((new Regex("se\\w+")).Replace("She sells sea shells", "X"))
printfn "%s" replaced
#light
open System
open System.Text.RegularExpressions
let replaced = ((new Regex("se\\w+")).Replace("She sells sea shells", "X"))
printfn "%s" replaced
fantom
replaced := Regex<|se\w+|>.split("She sells sea shells").join("X")
class SolutionXX
{
Void main()
{
replaced := Regex<|se\w+|>.split("She sells sea shells").join("X")
echo(replaced)
}
}
groovy
replaced = text.replaceAll(/se\w+/,"X")
text = "She sells sea shells"
replaced = text.replaceAll(/se\w+/,"X")
assert replaced == 'She X X shells'
Submit a new solution for
python
,
fsharp
,
fantom
,
groovy
...
There are 12 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
erlang
...)