Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

How to do this kind of find and replace?

Last post 03-17-2010, 8:29 AM by Srivas. 2 replies.
Sort Posts: Previous Next
  •  03-08-2010, 2:34 PM 60493

    How to do this kind of find and replace?

    Hello. 

     I have some text I want to rename in ms word in a certain way. There is a book with different verses and it starts like that: text 1. So I want to find all the texts with different numbers and rename them in a way that text 1 will be text 1.1.1, text 2 will be text 1.1.2 etc. till the end. Last verse will be text 1.1.something, so those first two numbers will remain the same. How to do that?

     

    Thank you. 

      

  •  03-16-2010, 7:10 PM 61244 in reply to 60493

    Re: How to do this kind of find and replace?

    You should find answers in a microsoft web site

    in msword, this is known as "multilevel list", you will find exactly what you need here http://office.microsoft.com/en-us/word/HA100650171033.aspx

    I just tried ms word office 2007  using "menu:paragraph->multilevel list", there is a list library with the style you are asking for.

    To renumber, select the number, right click and set the start number, or select them all, and set them to continue the previous one.

    you can also swap horizontally the numbers and the text by defining a new number format and select a left/right alignemnt for the number (left of the text, right of the text)

    You can also define the right style for your paragraphs and then apply the style to the existing text, so numbering will be consistent with the rules you define and all the text you use wil have a consistent numbering as you require.

    From http://office.microsoft.com/en-us/help/HA010873051033.aspx   Ms Word use a very primitive regular expression syntax. Note that the replacement will not work in numbers automatically handled in the styles. see above how to do it. A regular expression will not modify the characters generated by word.

    ^H   then click on more >> and cross "use wildcards"

    then enter the following expression  ("find what")

    ([!^13]@)([0-9]@)

    and this one ("replace with")

    1.1.\2 \1

    And then use next/replace where appropriate. 

    This changes the following text

    abcdefgh 1
    lksdjgkfljg 2
    ksdjlfksdj 3

    into

    1.1.1 abcdefgh

    1.1.2 lksdjgkfljg

    1.1.3 ksdjlfksdj

     

     

    I hope it answer your problem.

     

  •  03-17-2010, 8:29 AM 61290 in reply to 61244

    Re: How to do this kind of find and replace?

    Hi,

     thanks a lot, it works! Almost...

    But I'm just editing this text because it works till the first decimal, then the expression handles 1 and 0 separately and replace cannot be used anymore? How to fix that? How can I show that first part of the expression has a certain number of characters or certain word (word "text" has 4) and second part has certain, I can count that, number of digits? 

    I had to mess around a little, cause what I wanted was slightly different, but thanks to your regex code I could get exactly what I need (till the first decimal).

    I have "text 1" and I wanted "text 1.1.1(paragraph mark)text 1" with counter. I changed the replace with to: \11.1.\2^p\1\2 and it does the job.

     This is exactly what I need:

    "text 1" into "text 1.1.1^p text 1"

    "text 2" into "text 1.1.2^p text 2"

    and so on. 

    The reason why I need it is that first part, text 1.1.1, will have a level added and later indexed for quick search, I'm preparing rtf files for a digital library, later imported to another program designed for that purpose. 

View as RSS news feed in XML