Regex: Find all lines that contain two identical words, and delete up to the second word

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 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like