http://www.perlmonks.org?node_id=11160494

vincentaxhe has asked for the wisdom of the Perl Monks concerning the following question:

It's easy to guess what
[[a-z]&&[^aeiou]]
try to match, How perl do such thing, it's not included in primary perl pattern match knowledge.

Replies are listed 'Best First'.
Re: JAVA [[a-z]&&[^aeiou]] equivalence
by choroba (Cardinal) on Jul 10, 2024 at 08:59 UTC
    You need at least Perl 5.18 to use regex sets:
    #!/usr/bin/perl use warnings; use strict; use experimental qw{ regex_sets }; my @match = grep /(?[ [^aeiou] & [a-z] ])/, map chr, 0 .. 255; print "match = @match\n";
    Output:
    match = b c d f g h j k l m n p q r s t v w x y z
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Hello,

      nice info choroba. Glancing the doc you linked the following is even neater to my eyes:

      my @match = grep /(?[ [a-z] - [aeiou] ])/, map chr, 0 .. 255;

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Neat; learned something(regex sets).

      great!
Re: JAVA [[a-z]&&[^aeiou]] equivalence
by tybalt89 (Monsignor) on Jul 10, 2024 at 05:47 UTC
    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11160494 use warnings; $SIG{__WARN__} = sub { die @_ }; my @match = grep /(?=[^aeiou])[a-z]/, map chr, 0 .. 255; print "match = @match\n";

    Outputs:

    match = b c d f g h j k l m n p q r s t v w x y z
      it's a good approach,seems informal, I wonder is there a better way.

        Perl is intentionally informal. This is one of its greatest strengths.


        🦛

        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: JAVA [[a-z]&&[^aeiou]] equivalence
by hippo (Archbishop) on Jul 10, 2024 at 12:57 UTC
Re: JAVA [[a-z]&&[^aeiou]] equivalence
by LanX (Saint) on Jul 10, 2024 at 13:09 UTC
    > It's easy to guess what [[a-z]&&[^aeiou]] try to match,

    No, it's not, if you want good answers, please ask good questions.

    See also SSCCE!

    compare tybalt's reply in this respect, he shows input and expected output.

    This is not a Java board.

    Why haven't you at least linked to the correct Java documentation?

    > How perl do such thing

    There is more than one way to do it

    The details depend on it

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    A reply falls below the community's threshold of quality. You may see it by logging in.