Possible Duplicate:
RegEx match open tags except XHTML self-contained tags
I’m trying to retrieve a string being between delimiters…
Here the sample :
<TAG> x1 x2 y1 y2 </TAG>
I want my regex to return TAG
Could you also provide a link to a good regex documentation please ?
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:
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.
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.