What you are doing is possibly okay, as long as the tags are not recursive, otherwise it is not a good idea to do so! (a funny read).
If you are trying to write regex to get something in between those tags, and if that is the only exact case you wish to handle:
- You need to capture the name in tag 1. See this - this is done by enclosing in parentheses.
regex = "<(.*?)>"
.
The question mark is to make sure the shortest string (non-greedy) is matched - which is TAG in your case. If you just give <.*> it matches the whole expression, since regular expressions by default tend to match the longest string. The parentheses store the tag name so that it can be used in step 2.
- Then you need to make sure the closing tag has the same one - which needs a back reference to the captured group.(See this). So, here you need to write:
regex = "<(.*?)>.*</\1>"
The \1 is the back reference to the expression captured in the first set of parentheses.
I did not test it myself, but it should give you an idea of the concepts you need to use to write such an expression.