http://qs321.pair.com?node_id=686473


in reply to a regex which can detect if a string have all of some characters

The only non-looping/non-map solution I could come up with is the code-assertion counting technique:

... # the array positions of the chars are viewed as 'bits' # Bits: 1 1 1 1 ==> decimal 15 my @a = qw'a r z x'; use re 'eval'; our $t = 1; # $t will be modified within the regex # build the regex, essentially: /a(?{...})| b(?{...}) | c(?{...}) ... + /g my $p = 0; # position count variable during initialization my $expr = join'|', map quotemeta($_)."(?{\$t|=".(1<<$p++)."})", @a; # initialize before run $t = 0; my $mystring = 'areqrtyz'; # evaluate the regex in list context () and # look after the result in $t (comma operator =>, ) print 'no match' if () = $mystring =~ /$expr/g, $t != 15; ...

Regards

mwa