Suppose there are 3 text files with the following contents:

  1. cat * some text * cat * some text * ".

  2. fox * some text * fox * some text * ".

  3. dog * some text * dog * some text * ".

I have 2 questions:

  1. Is it possible to make such an expression that it finds only the second occurrence of the word, which is always the first in the file?

    1. cat * some text * cat * some text * ".

    2. fox * some text * fox * some text * ".

    3. dog * some text * dog * some text * ".

  2. I need to replace the second occurrence of the word. And replace the first word in translit (I myself doubt that this can be done using only regular expressions).

As a result, I need to get the following file contents:

  1. cat * some text * kot * some text * ".

  2. fox * some text * lisa * some text * ".

  3. dog * some text * sobaka * some text * ".

Is it possible to create a regular expression for this?

  • And to replace it with the first word in transliteration (I myself doubt that this can be done using only regular expressions) . - Wiktor Stribiżew 1:58 pm
  • @Wiktor Stribiżew What about the first question? Is it possible? - Nikita
  • Yes, it is simple. What are you going to use? - Wiktor Stribiżew 2:46 pm
  • In Notepad ++: \A(\s*(\w+)[\s\S]*?)\2([\s\S]*) -> $1KOT$3 . - Wiktor Stribiżew

0