Something like one of the approaches mentioned above is probably best, but if you want to roll your own regex, here's a way. The standard caution about metaquoting the strings that are used to make the regex if they might contain metacharacters applies.

>perl -wMstrict -le "my @anded = qw(foo bar baz); ;; my $jumbled = join ') (?= .*? ', @anded; $jumbled = qr{ \A (?= .*? $jumbled) }xms; print qq{any order: $jumbled}; ;; my $ordered = join ') .*? (?: ', @anded; $ordered = qr{ (?: $ordered) }xms; print qq{sequential: $ordered}; ;; while (<>) { chomp; print qq{string: '$_'}; print /$jumbled/ ? ' ' : 'no', ' match jumbled'; print /$ordered/ ? ' ' : 'no', ' match ordered'; print ''; } " any order: (?msx-i: \A (?= .*? foo) (?= .*? bar) (?= .*? baz) ) sequential: (?msx-i: (?: foo) .*? (?: bar) .*? (?: baz) ) "foo " string: '"foo "' no match jumbled no match ordered "foo bar ba" string: '"foo bar ba"' no match jumbled no match ordered "foo bar baz" string: '"foo bar baz"' match jumbled match ordered "baz foo bar" string: '"baz foo bar"' match jumbled no match ordered ^Z

In reply to Re: creating regular expressions dynamically from the command line by AnomalousMonk
in thread creating regular expressions dynamically from the command line by Anonymous Monk

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.