Results 1 to 12 of 12
  1. #1
    Lounger
    Join Date
    May 2003
    Location
    San Diego, California, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wildcards / Regular Expressions (MS Word)

    Anybody good with find & replace wildcards and regular expressions?

    I am trying to do a find and replace to insert a comma before the word "which".

    Find: "anyword space which" (no comma in the string)

    Replace: "anyword, which"

    I found some good articles"

    http://word.mvps.org/FAQs/General/UsingWildcards.htm

    http://office.microsoft.com/en-us/assistan...0873051033.aspx

    but my head is spinning a bit <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wildcards / Regular Expressions (MS Word)

    You don't need wildcards, much less reg ex's:
    Find what: #which
    Replace with: ,#which
    where the # is actually just a space, yes just type " which"
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    Lounger
    Join Date
    May 2003
    Location
    San Diego, California, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    Yes, but what about the case when the coma is already there? I would end up with ,, #which.
    This would work, if I followed it with a find and replace to change ,, to ,

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    Specify that you want to search using wildcards. Enter the following in the Find what box:
    <code>
    ([!,])( which)
    </code>
    <code>[!,]</code> means any character except a comma. The parentheses divide the Find what text into 2 parts that can be referred to in the Replace with box as 1 and 2. So enter the following in the Replace with box:
    <code>
    1,2
    </code>
    That is, the first part (which may not be a comma), followed by a comma, followed by the second part.

  5. #5
    Lounger
    Join Date
    May 2003
    Location
    San Diego, California, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    Perfect!

    Hans, Thank you for a careful concise explanation.

  6. #6
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wildcards / Regular Expressions (MS Word)

    ...but, there are lots of cases where you would not want a comma, for example, "of which, "in which", if fact most of the time. It would be practically impossible to automate. You must make a manual review. The biggest mistake people make with commas is their overuse. (esp. in California) <img src=/S/wink.gif border=0 alt=wink width=15 height=15> --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  7. #7
    Lounger
    Join Date
    May 2003
    Location
    San Diego, California, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    Sam, we call that a "California comma" <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    The macro that I am using asks before making the change. I could also add some code to remove the comma from "of which" and "in which", but for some reason I don't dictate those phrases often.

    I guess it is a case of which witch is which <img src=/S/brainwash.gif border=0 alt=brainwash width=15 height=15>

    Thanks!

  8. #8
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wildcards / Regular Expressions (MS Word)

    You, of course, mean "case of, which witch is, which!" <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15>
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  9. #9
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    Hans,

    I think this is the information that I've been looking for for awhile, but I need some help with the syntax. I basically need to figure out how to change a string in the middle of a search term.

    I most often need this when a chapter is renumberd (I'm a copy editor). The figures in, say, chapter 3 are labeled consecutively -- Figure 3-1, Figure 3-2, etc. If Chapter 3 becomes chapter 4, all of the figures need to be changed to Figure 4-1, Figure 4-2, etc. How can I do this?

    Would this be correct? Or does the use of real numbers in the S&R cause problems? Is there a limit to the number of sections you can create in the search box, or will word generate an error trying to look for a 14th section?

    Search: (Figure )3(-#)
    Replace: /14/2

    Thanks in advance to anyone who answers.
    Andy

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    I'd say you don't need anything fancy here - just enter

    Figure 3-

    in the Find what box, and

    Figure 4-

    in the Replace with box.

    BTW, why don't you use Word's built-in caption numbering? It'll keep track of numbering automatically.

  11. #11
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    Duh! Apparently I live in a world of mountains. Or maybe they're just molehills.

    We don't use Word's built-in caption numbering for 2 reasons:
    1) We would have to teach all of the authors how to use it -- which include a plethora of authors on Word 2000, Word 2003, Word for Mac, and, occasionally, OpenOffice.org.
    2) After the Word files have been edited, they go through an automation process that pours the text into QuarkXPress on Macs. The pouring process is tied into styles and funky character formatting and tabs and all kinds of stuff. In general, we don't use any "Automatic" processes that come out of Word.

    I know that there have been times that I've needed to change a character in the middle of a search term. Hopefully, when I come across it again, the info you've already given will be enough.

    Andy

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Wildcards / Regular Expressions (MS Word)

    > Hopefully, when I come across it again, the info you've already given will be enough.

    Don't hesitate to ask for help if you need it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •