Actually, I need a perl regular to work with keywords in the TextPipe program. Just go to the example, there are these kinds of keywords:

Buy food for fat elephant

Buy apples for skinny elephant

Buy carrots for normal elephant

It is necessary in each line with the help of regulars to select from the word "for" to the end of the line. Well, in TextPipe already remove or replace it all. To make the result lines like:

Buy food

Buy apples

Buy carrots

I read about perl for a long time, tried various options, but it wasn’t the only way and didn’t fit, tried the type for (. *?) $ But for some reason it removes everything to the end after the first "For".

Need help, thanks in advance!

  • Try this way to capture up to the end of the line -> for ([^\r\n]*+) - Visman
  • Understood nothing. At the beginning you write " select from the word" for "to the end of the line ." Your regulars are correct, in $ 1 it will capture everything from for to the end of the line. then you write " for some reason it removes everything to the end after the first for ". What is the difference between your first “to the end” that you want to receive, from that “to the end”, which does not suit you? - Mike
  • In my case, when I used for (. *?) $, The regular program selected and deleted everything after for until the end of the very last line, and not for each. That is, the result was just one line with "Buy food". for. + $ helped thanks! - PlanetControl

1 answer 1

You can solve it like this:

Greedy: (as many times as possible)

  1. ~ / for. + $ /
  2. ~ / for. * $ /

Lazy: (expanding as necessary)

  1. ~ / for. +? $ /
  2. ~ / for. *? $ /
  • But in this case there is no difference between them ... - Qwertiy ♦
  • Yes, but this is so that it is more expanded, asked, I wrote :) - And