Reputation: 1846
I have this regex that matches an empty span:
<span></span>
how can I rewrite it so that it matches span or div like tis:
<(div|span)></{THE CORRESPONDING TAG}>
performance is very important
just because everyone is asking, I use .NET regex...
Upvotes: 1
Views: 43
Reputation: 591
You use backreferences (depending on the regex implementation, these are noted differently, I just used backslash and number of the matching group, like e. g. Java and .net regexes use it, some other regex dialects use $1
instead of \1
):
<(div|span)></\1>
Upvotes: 4