realPro
realPro

Reputation: 1846

regex matching by group

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

Answers (1)

FrankPl
FrankPl

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

Related Questions