Here, I was playing with this.. there are bugs here..
use Test::Simple 'no_plan'; use strict; use constant DEBUG=> 1; sub debug; sub debug { print STDERR (+shift) ."\n" if DEBUG; } my $string = 'This is a great string here. Really. It even has an @ ch +ar.'; # no.. for my $chars( qw(12345 %!$*& ^ 9 x) ) # interestingly fails for ^ ok( ! string_has_chars($string => $chars ) , " we dont have '$chars +'"); } # yes.. for my $chars( qw(even has an @ char .Really) ){ ok( string_has_chars($string => $chars ) , " we do have '$chars'"); } sub string_has_chars { my $string = shift; my %char; ARG: for my $element (@_){ defined $element or next; if ( ref $element and ref $element eq 'ARRAY' ){ $element="@$element"; } for my $char ( split('',$element) ){ $char{$char}=0; } } my @chars = sort keys %char; debug("chars are [@chars]"); for my $c (@chars){ $string=~/$c/ or return; } return 1; }
On output..
leo@dali$ clear; perl /tmp/test.pl 

chars are 1 2 3 4 5
ok 1 -  we dont have '12345'
chars are ! $ % & *
ok 2 -  we dont have '%!$*&'
chars are ^
not ok 3 -  we dont have '^'
#   Failed test ' we dont have '^''
#   at /tmp/test.pl line 22.
chars are 9
ok 4 -  we dont have '9'
chars are x
ok 5 -  we dont have 'x'
chars are e n v
ok 6 -  we do have 'even'
chars are a h s
ok 7 -  we do have 'has'
chars are a n
ok 8 -  we do have 'an'
chars are @
ok 9 -  we do have '@'
chars are a c h r
ok 10 -  we do have 'char'
chars are . R a e l y
ok 11 -  we do have '.Really'
1..11
# Looks like you failed 1 test of 11.

In reply to Re: a regex which can detect if a string have all of some characters by leocharre
in thread a regex which can detect if a string have all of some characters 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.