There is definately MTOWTDT.

Since you have only requested assistance for two arguments, you might try something like:

if ($entry =~ /\Q$ARGV[0]\E/ && $entry =~ /\Q$ARGV[1]\E/) { # Do something }

The problem is that doesn't technically meet your requirements of ONE regexp.

This would be another way to do it with ONE regexp:

if ($entry =~ /(\Q$ARGV[0]\E.*\Q$ARGV[1]\E|\Q$ARGV[1]\E.*\Q$ARGV[0]\E) +/ { # Do something }

But that is going to be much slower and probably has about a dozen ways in which it won't work

My recommendation would be to standardize your data fields (i.e. first name, last name, etc) and then to use command line options to match them.

TelSearch.pl -f bill -l clinton
or
TelSearch.pl -l clinton -f bill

Hope this helps!

Cheers - L~R

Update: Corrected regexp that Enlil pointed out would only match one of the two arguments.


In reply to Re: regexp match arg1 AND arg2 by Limbic~Region
in thread regexp match arg1 AND arg2 by Jaap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.