I have a problem that I think could (should?) be possible using regular expressions. I've been using regular expressions for some time, so I have some experience with it, but I can't find a way to make this work correctly.
Say I have a long string of different fruits:
Quote:
apples bananas pears oranges grapes mangos melons
and I need the first part of it, up until AT LEAST one of a few keywords occur:
Although grapes and melons are not keywords, they should still be omitted. I only want the text before pears included. The order of all the fruits could be random and as such, the regex should still work.
I tried this, but it doesn't work as I expect:
(.+)(pears|oranges|mangos).*
Instead of matching any of the words, it includes as much as it can until the last keyword it can match - I need it to basically do the opposite.
(By the way, the string could theoretically contain none of the keywords, where I would like to use the entire string instead)
I'm doing this in a perl-script - Any suggestions are welcome