I have the following Java code:
str = str.replaceAll(\"<.*?>.*?|<.*?/>\", \"\");
This turns a String like so:
While there are other correct answers, none give any explanation.
The reason your regex <.*?>.*?|<.*?/>
doesn't work is because it will select any tags as well as everything inside them. You can see that in action on debuggex.
The reason your second attempt <.*?>|<.*?/>
doesn't work is because it will select from the beginning of a tag up to the first close tag following a tag. That is kind of a mouthful, but you can understand better what's going on in this example.
The regex you need is much simpler: <.*?>
. It simply selects every tag, ignoring if it's open/close. Visualization.