vitoco has asked for the wisdom of the Perl Monks concerning the following question:
I have a file with many records. Fields are delimited by tab. One of the fields is a list of comma separated keywords. What I want is to extract only those records that have keywords according to an expression given on runtime.
Is there a package available that can create a single regular expression starting from a string like the following ones?
moe&(shemp|curly|joe)&larry (tom&jerry)|(sylvester&tweety)
If I have to do that by myself, I can manage the ORs with something like this in the regex:
\b(one|two|three)\b
but I'm not sure how to handle the ANDs. I've done some tests with advanced expressions like (?=word) without understanding what is really going on.
I also thought on sorting each keywords list to allow simple regex being written as \bone\b.*\btwo\b, but is useless if I want to search for:
olive&(popeye|bluto)
Hints, please?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: AND and OR on Regular Expressions
by busunsl (Vicar) on Aug 25, 2009 at 14:07 UTC | |
Re: AND and OR on Regular Expressions
by ikegami (Patriarch) on Aug 25, 2009 at 14:32 UTC | |
by JavaFan (Canon) on Aug 25, 2009 at 15:55 UTC | |
by ikegami (Patriarch) on Aug 25, 2009 at 16:36 UTC | |
by JavaFan (Canon) on Aug 25, 2009 at 20:41 UTC | |
by ikegami (Patriarch) on Aug 25, 2009 at 21:20 UTC | |
| |
Re: AND and OR on Regular Expressions
by Anonymous Monk on Aug 25, 2009 at 14:10 UTC | |
Re: AND and OR on Regular Expressions
by vitoco (Hermit) on Aug 25, 2009 at 17:22 UTC | |
by vitoco (Hermit) on Aug 25, 2009 at 21:18 UTC | |
by grizzley (Chaplain) on Aug 26, 2009 at 07:19 UTC | |
by vitoco (Hermit) on Aug 26, 2009 at 14:51 UTC |