Results 1 to 6 of 6

Thread: Find/Replace

  1. #1
    5 Star Lounger
    Join Date
    Aug 2006
    Posts
    784
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a code in MS Word's Find and Replace dialogue for "p(no.)(no.). ", where (no.) is any digit from 0-9? I'd like to replace that with "^l(no.)(no.). "

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by jmt356 View Post
    Is there a code in MS Word's Find and Replace dialogue for "p(no.)(no.). ", where (no.) is any digit from 0-9? I'd like to replace that with "^l(no.)(no.). "
    I'm going to assume that first p is a paragraph break. Please edit my code if that is not the case.

    It's easy to do the find part using

    Code:
    Find what: ^p^#^#.
    But replacing is more tricky. In order to replace a portion of the found text and preserve the rest, you need to enable wildcards. But then ^p and ^# are no longer legal in the find what string. So that requires you to use a different syntax that is closely similar in effect but not identical (^13 picks up UNIX-style line breaks as well as Windows style line breaks):

    Code:
    Find what: ^13([0-9]{2}\.)
    Replace with: ^l\1
    Note: the \1 copies the text match from the first parenthetical in the find what expression.

    Edit: to match and replace a trailing space, add that after the period.

  3. #3
    5 Star Lounger
    Join Date
    Aug 2006
    Posts
    784
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a document with the Arabic word for "article" followed by an article number appearing over two hunderd times. I want to put a hard paragraph mark (enter; line break; ^p) between the article, the article number, and the text of teh article that follows so that the text of the article that follows will be below the word "article" and the corresponding article number.

    I enabled wildcards adn used this code:
    Find: {(2)} المادة
    Replace: \1^p

    When I attempt a search, I get this message: "The Find What text contains a Pattern Match expression which is not valid."

    What's not valid about it? And anyway, what does {(2)} mean? Whenever I search for that, I get any single character or space, regardign of whether there is a 2 in the parentheses or any other number, including 10.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi jmt,

    What's the actual string preceding the 'المادة' that you're searching for? Your find code certainly won't work as a wildcard Find expression - the {(2)} isn't a valid expression. Assuming you're looking for '(#) المادة', where the # is a 1-3 digit number, try using:
    Find = '(\([0-9]{1,3}\) )?????? '
    Replace = '\1'
    (without the single quotes)
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    5 Star Lounger
    Join Date
    Aug 2006
    Posts
    784
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am now trying to take every reference in my document to "(no.) المادة", where (no.) is any number from 1 - 999, and replace it with "^p(no.) المادة", such that before the number (after the number if you're thinking linearly right to left as in Arabic) there will be a hard line break.

    I was going to first go after the two digit numbers and then focus on the three digit numbers and then the one digit numbers. So focusing on the two digit numbers, I tried:
    Find: ({2}[0-9]) المادة
    Replace with: \1^p

    However, Word was replacing the selection with just the number followed by a hard enter instead of the word المادة followed by the number followed by a hard enter. Is Word unable to replicate the Arabic word using wildcards?

    Also, macropod, for some reason, I'm still getting a message that the search item I'm looking for was not found when I search for (\([0-9]{1,3}\) )??????

    I'm just going to attach the document. Please note that I already inserted hard paragraph breaks (^p) into the first few articles, but around article 26 (المادة 26) there is no hard paragraph break after the article number. If anyone could figure out the exact code that would work, it would be great, especially if it is a single code that coudl be used for one, two, or three digit numbers.
    Attached Files Attached Files

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi jmt,

    I'm not surprised the Find didn't work, since the numbers aren't enclosed in parentheses, which is what my Find code was based on. As I said:
    Assuming you're looking for '(#) المادة' ...
    . Your post was quite ambiguous as to what you were looking for.

    For your purposes, you should be able to use a wildcard Find/Replace, with:
    Find = (المادة )([0-9]{1,3})
    Replace = \2\1^p

    Finally, I see you've been posting on the same topic at: http://www.eileenslounge.com/viewtopic.php?f=26&t=3910
    For cross-posting etiquette, please see: http://www.excelguru.ca/node/7
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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