View Single Post
 
Old 03-30-2016, 05:12 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by rpb925 View Post
.Replacement.Text = "\3"
.Execute Replace:=wdReplaceAll

How does the replace work? what is \3 why does Greg use \2 and is this where the original tags are deleted?
A wildcard Find can use brackets () to delineate certain segments of the expression for re-use. The Find expression:
.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"
has 3 such delineated segments and it is the 3rd of these that gets re-used for the replacement. In Greg's code, there were just 2 such delineations and the 2nd gets reused.
Quote:
Originally Posted by rpb925 View Post
.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"

What is (*)\1/\2 doing it looks like jibberish?
Not jibberish; just clever.

The:
(\<" & arrTerms(i) & ")(\>)
defines 2 segments of the Find expression for re-use: the string comprising the '<' and array entry for the 1st segment; and the '>' for the 2nd segment. A '\' is required before certain Find characters, including < and >.

The:
(*)
defines as a 3rd segment whatever follows the 2nd segment that precedes a repeat of the 1st segment, as indicated by the \1.

The:
\1/\2
says to repeat the 1st segment, insert the /, then repeat the 2nd segment.

FWIW:
.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"
is the same as:
.Text = "\<" & arrTerms(i) & "\>(*)\<" & arrTerms(i) & "/\>"
for which the replacement would be \1.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote