Reputation: 43863
I have this regex
<SharePointWebControls:(\w+).*?fieldname="(.*?)".*?\s*<\/SharePointWebControls:(?:\w+).*?>
Notice the two parts of it (\w+)
and (?:\w+)
. This regex will match somethign even when these two are different. How can I force it so the matched area has to be the same for these two groups?
Thanks
Upvotes: 2
Views: 26
Reputation: 785256
You can use back-reference to matched groups using \1
:
<SharePointWebControls:(\w+).*?fieldname="(.*?)".*?\s*<\/SharePointWebControls:\1>
Here \1
in later part is actually back-reference to first capturing group which is being captured by (\w+)
.
Upvotes: 3