Suppose we have a list of the following:
l={"applejuice","lemon_juiceginger"}
How can one modifies this to read as:
{"apple:juice","lemon_juice:ginger"}
I have tried StringRiffle[]
but wasn't so successful.
We can use a slight modification of the function reArrange
from this answer:
ClearAll[reArrange2]
reArrange2[s_String] := ## & @@
StringCases[s, StartOfString ~~ beg__ ~~ w__ ~~ EndOfString /;
(And @@ DictionaryWordQ /@ {w, ## & @@ StringSplit[beg, "_"]}) :>
StringRiffle[{beg, w}, ":"]]
reArrange2 /@ l
{"apple:juice", "lemon_juice:ginger"}
:
? The example is not self-explanatory. $\endgroup$lemon_juice
where there is "_". $\endgroup$"lemon_juiceginger"
should be"lemon:_juice:ginger:"
. $\endgroup$