Suppose I have an original string that looks like:

str1 = "erewrer<.rer>r33e<erer>re<><>rer\nrer<ew212>"

I want to get rid of all those discrete <...>s to get


I tried StringReplace

StringReplace[str1, "<" ~~ __ ~~ ">" -> ""]

but it produced


which is the result with the outermost <...> removed.

What should I do?


You need to add Shortest[] to get the shortest consistent match(es), since Mathematica uses Longest[] (i.e. a greedy match) by default:

              Shortest["<" ~~ __ ~~ ">"] -> ""]
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.