regular-expressions – Tell me about the perl regex


Actually, I need a perl regex to work with keywords in the TextPipe program. I'll go straight to an example, there are such keywords:

Buy food for fat elephant

Buy apples for skinny elephant

Buy carrots for normal elephant

It is necessary to select from the word "for" to the end of the line with the help of regular lines. Well, in TextPipe, you have already removed or replaced all this. So that the result is lines like:

Buy food

Buy apples

Buy carrots

I read about perl for a very long time, tried different options, but not one and did not fit, tried the for (. *?) $ Type, but for some reason it deletes everything to the end after the first "For".

Need help, thanks in advance!


You can solve it like this:

Greedy: (as many times as possible)

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

Lazy: (expanding as needed)

  1. ~ / for. +? $ /
  2. ~ / for. *? $ /
Scroll to Top