Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #20017

    Sal Jel
    Participant

    I have more than 1000 files. Each file contain a unique word called “word1”. Also each file contain a unique word called “word3” located between “word2” and “word4”. Here is a sample structure.
    —————————
    text text text word1 text
    text text
    text text
    text word2word3word4 text text
    —————————
    I want to do a global find and replace to change the above example to become:
    ————————–
    text text text word3 text
    text text
    text text
    text word2word3word4 text text
    ————————-

    As you can see, word3 got copied and replaced word1.
    Please note that word1 is always called word1 in all files. word2 and word4 are also always call the same. But word3 changes names in different files. So if you can give me a regex which searches for the word between “word2” and “word4”, captures it, and then replaces “word1” with “word3”. I appreciate your help.

    #20019

    Yutaka Emura
    Keymaster

    I am not exactly sure, but I hope this is correct.

    In the Replace dialog box, click the “Customize…” button, and set 4 or more in the Additional Lines to Search for Regular Expressions text box.

    Set the Use Regular Expressions check box

    Find:

    word1((.|\n)*?)word2(.*?)word4
    

    Replace with:

    \3\1word2\3word4
    

    Thanks!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.