0

I have this 2 lines:

  1. litere bebe litere oana stilou mancare acasa carte litere

  2. litere bebe oana stilou mancare acasa carte litere

The word litere is repeated 3 times in the first line, and the same word is repeated 2 times in the second line. Also, the word stilouis present in both lines.

So, I want to find all lines that contain two identical words (litere), but delete up to the second word stilou

3
  • 1
    In "find and delete all lines that contain two identical words (litere)", does "two" mean "exactly two occurrences" or "at least two occurrences"? If ` stilou` was added at the very end of the second line, should "up to the second word stilou" refer to the first or to the second occurrence of stilou? Commented Jun 28, 2021 at 7:45
  • I update my post. It is about 2 or 3 occurences of the word litere and one occurence of word stilou.
    – Just Me
    Commented Jun 28, 2021 at 7:53
  • What is your expected result?
    – Toto
    Commented Jun 28, 2021 at 8:06

1 Answer 1

0

My solution is this one:

  • Ctrl+H
  • Find what: (litere)(?=.*\1).*(stilou)
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

and if I want to keep the words litere and stilou, and delete everything bewteen them, I may use this regex:

  • Ctrl+H
  • Find what: (litere)(?=.*\1).*(stilou)
  • Replace with: \1 \2
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all
2
  • 1
    The alternation |\2 doesn't make sense, you can remove it
    – Toto
    Commented Jun 28, 2021 at 8:23
  • yes, indeed @Toto . I update my anwer, thanks
    – Just Me
    Commented Jun 28, 2021 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .