On Wed, May 16, 2018 at 9:05 PM, Todd Chester <toddandma...@zoho.com <mailto:toddandma...@zoho.com>> wrote:


    On 05/16/2018 07:58 AM, Timo Paulssen wrote:

        On 16/05/18 00:10, ToddAndMargo wrote:

            What would the syntax be for d..z, but not g or m?


        You can subtract [gm] from [d..z] like this:

              say "c" ~~ /<[d..z]-[gm]>/;
              say "d" ~~ /<[d..z]-[gm]>/;
              say "f" ~~ /<[d..z]-[gm]>/;
              say "g" ~~ /<[d..z]-[gm]>/;



    Something is wrong:

    $ p6 'if "dgm" ~~ /<[d..z]-[gm]>/ {say "yes"}else{say "no"};'
    yes

    I want it to fail if it find g or m

    :'(


    $ alias p6
    alias p6='perl6 -e'




On 05/16/2018 06:10 PM, Brandon Allbery wrote:
> You need to be more careful with regexes (any regexes). Your character
> class matches if any character in the string matches, so 'd' satisfies
> it and the rest of the string is ignored. If you want to ensure *no*
> character matches, then say so:
>
> pyanfar Z$ 6 'if "dgm" ~~ /^<[d..z]-[gm]>*$/ {say "y"} else {say "n"}'
> n
>
>


`^` for start at the beginning and `*$` for keep going all the
way to the end.

Now I understand.  Thank you!

$ p6 'if "dgm" ~~ /^<[d..z]-[gm]>*$/ {say "y"} else {say "n"}'
n

$ p6 'if "def" ~~ /^<[d..z]-[gm]>*$/ {say "y"} else {say "n"}'
y

$ p6 'if "abc" ~~ /^<[d..z]-[gm]>*$/ {say "y"} else {say "n"}'
n

Reply via email to