[duxuser] Re: Search and Replace in Microsoft Word

  • From: "Joanmarie Diggs" <joanmarie.diggs@xxxxxxxxxxx>
  • To: <duxuser@xxxxxxxxxxxxx>
  • Date: Sat, 9 Apr 2005 12:13:22 -0400

You said:  search for "^p^p" followed by small letters and change the "^p"
to " ".  Question:  Did you want to change just one ^p to a space, or both
of them?  And if the latter, did you want to replace each ^p with a space,
or the combined ^p^p with a single space.  Since I need to assume something,
I'm going to assume that you want to replace both ^p's with a single space.
In which case.... Give this a shot:  Check the checkbox to use Wildcards.
Then search for:  (^13{2})([a-z]) and replace it with: a space followed by
\2
 
Explanation:  
 
* When you enable wild cards, you can take advantage of *some* of the
elements of regular expressions, but not all.  
* When you enable wild cards, you can no longer use things like ^p to search
for characters.  
 
So our first challenge is to figure out how to search for the carriage
returns now that ^p is not an option and the regular expression way of doing
things (i.e. \n) isn't valid in Word.  The solution:  ^13.  When wildcards
are enabled the caret says, "Look for this ANSI character (in decimal)."  13
is the ANSI character code (again in decimal) for carrage return.  So ^13 is
your new ^p.  You need two of them.  I suppose you could do ^13^13, but
since I'm taking the time to write this, we might as well get all of our
options on the table.  After all, what if for some bizarre reason, your
document contained 10 carriage returns rather than 2.  Do you really want to
type out ^13 10 times?  Or, perhaps more realistically, you might have a
document that has either 2 or 3 carriage returns.  How do you specify that?

 
{n,m} is the regexp way of saying "at least n of these, but no more than m
of them".  {n} says "exactly n of these".  So ^13{n} is what you need.
^13{10} would address my first hypothetical example and ^13{2,3} my second.
If you wanted to search for at least 2 carriage returns with an unknown
maximum, you would use ^13{2,}
 
[range of letters] is the regexp way of saying find any character in this
range.  Capitalization counts.  So [a-z] says find any single lower-case
letter.
 
Put it all together and ^13{2}[a-z] will search for all small letters that
follow two carriage returns.  That's half the battle.  
 
Our next challenge is to figure out what on earth to replace it with.
Sadly, you cannot do something like [a-z] to tell Word "if you find a lower
case letter, please leave it alone and just get rid of the carriage
returns."  What you can do however, is cause Word to treat elements in your
search term as objects.  What you want to do is replace the 2 carriage
returns with a single space if they are followed by a lower case letter.  So
go back to the Find What edit box and surround the ^13{2} in parentheses.
Do the same for your lowercase letter, [a-z].  Thus (^13{2})([a-z]).
Putting things in parantheses is what allows you to refer to them as
objects.  ^13{2} is object number 1 and [a-z] is object number 2. When you
find 2 carriage returns (object number 1) followed by a lower case letter
(object number 2), you want to replace object number 1 with a single space
and leave object number 2 alone.  Hence your replace term is a space
followed by \2.  \2 being the Word way to say "object number 2"
 
I hope this makes sense and solves your problem.  Take care.
Joanie

  _____  

From: duxuser-bounce@xxxxxxxxxxxxx [mailto:duxuser-bounce@xxxxxxxxxxxxx] On
Behalf Of Rick Boggess
Sent: Saturday, April 09, 2005 9:15 AM
To: duxuser@xxxxxxxxxxxxx
Subject: [duxuser] Search and Replace in Microsoft Word


I was recently doing some document clean up in Word before importing it into
Duxbury. I had instances where there were blank lines followed by a capital
letter and blank lines followe by a small letter.  I wanted to search for
"^p^p" followed by small letters and change the "^p" to " ".  I looked at
the Word help file and foun all kinds of advanced features but there did not
seem to be one which worked for this particular situation.  I would
appreciate hearing from anyone who might have suggestions for dealing with
this.
 
Thanks.
Rick Boggess   

Other related posts: