This is a problem related to How to use StringReplace "from bottom to global"?
The answer of @J.M. works well for "<...>" styles :
StringReplace["erewrer<.rer>r33e<erer>re<><>rer\nrer<ew212>",
Shortest["<" ~~ __ ~~ ">"] -> ""]
"erewrerr33ererer\nrer"
Now suppose I have a string
strinput="It will only take a moment/minute/second"
I want to get
stroutput="It will only take a second"
So I tried
StringReplace[#, {Shortest[" " ~~ ___ ~~ "/"] ->
" "}] &@"It will only take a moment/minute/second"
"It minute/second"
Strangely the whole "will only take a moment/" was eaten. Why this happen? What should I do?
{" " ~~ Except[" "] .. ~~ "/" -> " "}and take a look here: 72283 – Kuba Jun 29 '16 at 08:03StringReplace[#, {xx : Shortest[" " ~~ ___ ~~ "/"] :> (Print[xx]; " ")}] &@"It will only take a moment/minute/second"and you can see exactly what's matched (and that it's doing what you asked it to in this case). – ciao Jun 29 '16 at 08:06