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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |