Re: Need match character help

2018-05-20 Thread ToddAndMargo

On 05/20/2018 04:16 PM, yary wrote:
PRM's suggestion was "/inverting the entire regex -- i.e., instead of 
matching finding things that do match, exclude the things that don't ... 
use !~~ or some similar logic to get the strings wanted/" which IMO is 
an excellent idea. Your implementation didn't take the inversion into 
account- try this


p6 'if "hgm" *!~~* / gm | <-[d..z]> / {say "y"} else {say "n"}'




p6 'if "hgm" !~~ / gm | <-[d..z]> / {say "y"} else {say "n"}'
n

$ p6 'if "cgm" !~~ / gm | <-[d..z]> / {say "y"} else {say "n"}'
n

$ p6 'if "zgm" !~~ / gm | <-[d..z]> / {say "y"} else {say "n"}'
n

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


Thank you!


Re: Need match character help

2018-05-20 Thread yary
PRM's suggestion was "*inverting the entire regex -- i.e., instead of
matching finding things that do match, exclude the things that don't ...
use !~~ or some similar logic to get the strings wanted*" which IMO is an
excellent idea. Your implementation didn't take the inversion into account-
try this

p6 'if "hgm" *!~~* / gm | <-[d..z]> / {say "y"} else {say "n"}'


Re: Need match character help

2018-05-20 Thread Patrick R. Michaud
On Sun, May 20, 2018 at 03:02:34PM -0700, ToddAndMargo wrote:
> On 05/20/2018 10:40 AM, Patrick R. Michaud wrote:
> > On Fri, May 18, 2018 at 03:28:20PM +0200, Timo Paulssen wrote:
> > > On 18/05/18 13:30, The Sidhekin wrote:
> > > > 
> > > >    / ^ <[d..z]>* $/
> > > 
> > > That's pretty good! Putting the beginning-of-string anchor ^ anywhere
> > > but the very start is surely an advanced move :)
> > 
> > FWIW, sometimes I think it's worth inverting the entire regex -- i.e., 
> > instead of matching finding things that do match, exclude the things that 
> > don't:
> > 
> > / gm | <-[d..z]> /
> > 
> > This regex will match any string containing the sequence "gm" or any 
> > character that isn't in the range "d".."z", which is the inverse of what 
> > was required (strings containing only "d".."z" and never "gm").  Then use 
> > !~~ or some similar logic to get the strings wanted.
> > 
> > I recognize that this approach might not fit well in all cases, but it's 
> > another (perhaps cleaner) approach to getting what's wanted.
> 
> Something is wrong.  "h" is in the exclude list.
> 
> $ p6 'if "hgm" ~~ / gm | <-[d..z]> / {say "y"} else {say "n"}'
> y

The string "hgm" is in the "not include" list for the other regex as well 
(because it contains "gm"):

$ perl6 -e 'if "hgm" ~~ /  ^ <[d..z]>* $/ { say "n" } else { say 
"y" }'
y


Pm


Re: Need match character help

2018-05-20 Thread ToddAndMargo

On 05/20/2018 10:40 AM, Patrick R. Michaud wrote:

On Fri, May 18, 2018 at 03:28:20PM +0200, Timo Paulssen wrote:

On 18/05/18 13:30, The Sidhekin wrote:


   / ^ <[d..z]>* $/


That's pretty good! Putting the beginning-of-string anchor ^ anywhere
but the very start is surely an advanced move :)


FWIW, sometimes I think it's worth inverting the entire regex -- i.e., instead 
of matching finding things that do match, exclude the things that don't:

/ gm | <-[d..z]> /

This regex will match any string containing the sequence "gm" or any character that isn't in the range 
"d".."z", which is the inverse of what was required (strings containing only "d".."z" and never 
"gm").  Then use !~~ or some similar logic to get the strings wanted.

I recognize that this approach might not fit well in all cases, but it's 
another (perhaps cleaner) approach to getting what's wanted.

Pm





Something is wrong.  "h" is in the exclude list.

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





--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Need match character help

2018-05-20 Thread Patrick R. Michaud
On Fri, May 18, 2018 at 03:28:20PM +0200, Timo Paulssen wrote:
> On 18/05/18 13:30, The Sidhekin wrote:
> >
> >   / ^ <[d..z]>* $/
> 
> That's pretty good! Putting the beginning-of-string anchor ^ anywhere
> but the very start is surely an advanced move :)

FWIW, sometimes I think it's worth inverting the entire regex -- i.e., instead 
of matching finding things that do match, exclude the things that don't:

   / gm | <-[d..z]> /

This regex will match any string containing the sequence "gm" or any character 
that isn't in the range "d".."z", which is the inverse of what was required 
(strings containing only "d".."z" and never "gm").  Then use !~~ or some 
similar logic to get the strings wanted.

I recognize that this approach might not fit well in all cases, but it's 
another (perhaps cleaner) approach to getting what's wanted.

Pm


Re: Need match character help

2018-05-18 Thread ToddAndMargo
On Fri, May 18, 2018 at 1:32 PM, ToddAndMargo > wrote:


On 05/18/2018 01:22 PM, ToddAndMargo wrote:

To match particular characters.


that should have been
 To match particular characters or phrases

I am using "phrase" here in the English language meaning, not
the programming meaning




On 05/18/2018 04:14 PM, yary wrote:

Do you want "abcdef" to say "y" or "n"?

-y





Any digit, any decimal point, and "rc", any "a", OR any "b":


Re: Need match character help

2018-05-18 Thread ToddAndMargo

On 05/18/2018 01:22 PM, ToddAndMargo wrote:

To match particular characters.


that should have been
To match particular characters or phrases

I am using "phrase" here in the English language meaning, not
the programming meaning


Re: Need match character help

2018-05-18 Thread ToddAndMargo

On 05/15/2018 07:05 AM, Timo Paulssen wrote:

On 15/05/18 13:49, ToddAndMargo wrote:

Hi All,

This should be a "no".  What am I doing wrong?

$ perl6 -e 'my $x="rd"; if $x~~/<[rc]+[a]+[b]+[.]>/ {say
"yes"}else{say "no"}'
yes


Many thanks,
-T


what you've put in your regex here is a character class combined of four
individual ones "added together";

it matches a single letter that is either an "r", a "c", an "a", a "b",
or a ".". Character classes always match only a single character, if you
want it to match more, you will have to use a quantifier, like "+", "*",
or "**". Since your regex is not anchored, it will accept any of those
characters in any spot, so strings like "hello a" will match, too.

It seems like what you want is actually this:

/rc | a | b | "."/

which matches if either "rc", "a", "b" or "." exist somewhere in the string.

If you want to accept only if the full string is "rc", "a", "b" or ".",
you'll have to put anchors in the front and back, and put brackets
around the inner part, so that the ^ and $ refer to the whole
alternation, not just the ^ to the first variant and $ to the last variant.




Thank you!

To match particular characters.  Any digit, any decimal point, and "rc", 
any "a", OR any "b":


$ p6 'if "24b5" ~~ /\d |rc | a | b | "."/ {say "y"} else {say "n"}'
y

$ p6 'if "5" ~~ /\d |rc | a | b | "."/ {say "y"} else {say "n"}'
y

$ p6 'if "def" ~~ /\d |rc | a | b | "."/ {say "y"} else {say "n"}'
n

$p6 'if "rc" ~~ /\d | rc | a | b | "."/ {say "y"} else {say "n"}'
y

$ p6 'if "cr" ~~ /\d | rc | a | b | "."/ {say "y"} else {say "n"}'
n

$ p6 'if "rc" ~~ /\d | rc | a | b | "."/ {say "y"} else {say "n"}'
y


Re: Need match character help

2018-05-18 Thread Timo Paulssen
On 18/05/18 13:30, The Sidhekin wrote:
> On Thu, May 17, 2018 at 12:51 PM, Timo Paulssen  > wrote:
>
> character classes are fundamentally the wrong thing for "phrases",
> since they describe only a character.
>
>
>   You were right the first time.

I'm not sure what you're referring to here?

>  [...]
>
>   Somewhat interesting exercise, but this kind of rephrasing doesn't
> scale well for longer phrases, is hard to automate (given a phrase,
> which character classes need we use?), and it's already pretty hard to
> read.

That's true, it's probably not sensible to do every regex this way. I'm
not sure how I could have done it better, though.

>   If this requirement needs to be expressed in a single regex, here's
> what I'd use (quickly translated from Perl5, then tested to get rid of
> translation errors):
>
>   / ^ <[d..z]>* $/
>
>   ... or, with comments:
>
>   / # not containing the phrase "gm" anywhere from here,
>    ^ <[d..z]>* $ # match the whole string, containing only letters d
> through z
>   /

That's pretty good! Putting the beginning-of-string anchor ^ anywhere
but the very start is surely an advanced move :)

  - Timo


Re: Need match character help

2018-05-18 Thread The Sidhekin
On Thu, May 17, 2018 at 12:51 PM, Timo Paulssen  wrote:

> character classes are fundamentally the wrong thing for "phrases", since
> they describe only a character.
>

  You were right the first time.


> Your current regex (before changing [gm] to ["gm"]) was expressing "from
> the start of the string, there's any amount of characters d through z (but
> neither g nor m) and then the end of the string", which can be more easily
> expressed as "the whole string contains only letters d through z (but
> neither g nor m)".
>
> What you apparently want is "the whole string contains only letters d
> through z, but never the phrase 'gm'", which - in order to get to a working
> regex - we can rephrase as "the whole string contains only letters d
> through z and no occurrence of g is followed by an m". Let's turn that into
> a regex:
>
> /^ # Require the match to start at the beginning of the
># string so nothing can sneak in before that.
> [  # Everything in this group will be matched a bunch
># of times.
> |  <[d..z]-[g]>  # either anything between d and z, with no
>  # further restrictions, except for g.
> |  g  # If there's a g, it must not be followed
>  # by an m.
> ]* # end of the group, allow the things in the group to
># occur any amount of times.
> $/ # Require the match to end at the end of the string,
># so nothing at the end can sneak in.
>
  Somewhat interesting exercise, but this kind of rephrasing doesn't scale
well for longer phrases, is hard to automate (given a phrase, which
character classes need we use?), and it's already pretty hard to read.

  If this requirement needs to be expressed in a single regex, here's what
I'd use (quickly translated from Perl5, then tested to get rid of
translation errors):

  / ^ <[d..z]>* $/

  ... or, with comments:

  / # not containing the phrase "gm" anywhere from here,
   ^ <[d..z]>* $ # match the whole string, containing only letters d
through z
  /


Eirik


Re: Need match character help

2018-05-17 Thread Norman Gaywood
Nice RE tutorial :-)

/^ [ | <[d..z]-[g]> | g ]* $/

One question I have is what is the first | for?

On Thu, 17 May 2018 at 21:10, Timo Paulssen  wrote:

> The description perhaps doesn't point out clearly enough: the reason why
> the stuff inside the [ ] will match any amount of times is only the * at
> the end, the [ ] is only there because otherwise the regex would instead
> match something you didn't mean at all. If you're interested, read on for
> an explanation, but it might actually be more confusing than helpful:
>
> The resulting regex means "either the beginning of the string is followed
> by any letter from d to z except g, or there's a g that's either not before
> an m, or it is, and followed by the end of the string".
>
> That's because now the | would not only separate the ^ and $ anchors into
> becoming alternatives, but the * would cling to the  which is
> now allowed to not match at all (because it's a * and not a +).
>
> Also, putting a quantifier (which is what * and + are called) on a before
> or after assertion makes no sense and probably leads to an infinite loop
> (the regex engine tries to make you proud by matching it as often as it
> possibly can. which if the assertion is true, is infinitely often. it is
> very diligent, but it does not really think much about what it does).
>
> Hope that helps
>   - Timo
>
> On 17/05/18 12:51, Timo Paulssen wrote:
>
> character classes are fundamentally the wrong thing for "phrases", since
> they describe only a character.
>
> Your current regex (before changing [gm] to ["gm"]) was expressing "from
> the start of the string, there's any amount of characters d through z (but
> neither g nor m) and then the end of the string", which can be more easily
> expressed as "the whole string contains only letters d through z (but
> neither g nor m)".
>
> What you apparently want is "the whole string contains only letters d
> through z, but never the phrase 'gm'", which - in order to get to a working
> regex - we can rephrase as "the whole string contains only letters d
> through z and no occurrence of g is followed by an m". Let's turn that into
> a regex:
>
> /^ # Require the match to start at the beginning of the
># string so nothing can sneak in before that.
> [  # Everything in this group will be matched a bunch
># of times.
> |  <[d..z]-[g]>  # either anything between d and z, with no
>  # further restrictions, except for g.
> |  g  # If there's a g, it must not be followed
>  # by an m.
> ]* # end of the group, allow the things in the group to
># occur any amount of times.
> $/ # Require the match to end at the end of the string,
># so nothing at the end can sneak in.
>
> Important things to note here:
>
>-  (spoken as "do not match before an m") will be fine with
>occurrences at the end of the string, too.
>- we don't remove the m from the character class any more, we only
>keep the g in there, because m can be in the string without restrictions;
>if there is an m after a g, our regex will already have failed before it
>even reaches the m, and all other cases are fine (like dm or fm or hm).
>- you are allowed to put a | not only between things, but also at the
>very front. This is allowed in the syntax so that you can line things up
>vertically like I did. Think of it as similar to allowing a , after the
>last element in a list, like with [1, 2, 3, 4, ]
>
> hi
> Match: 「hi」
> bleh
> Match: Nil
> fog
> Match: 「fog」
> dm
> Match: 「dm」
> fm
> Match: 「fm」
> hm
> Match: 「hm」
> gm
> Match: Nil
> rofl
> Match: 「rofl」
> dddg
> Match: 「dddg」
> 
> Match: 「」
> 
> Match: 「」
>
>
> Hope that helps!
>   - Timo
>
>
>

-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


Re: Need match character help

2018-05-17 Thread Timo Paulssen
The description perhaps doesn't point out clearly enough: the reason why
the stuff inside the [ ] will match any amount of times is only the * at
the end, the [ ] is only there because otherwise the regex would instead
match something you didn't mean at all. If you're interested, read on
for an explanation, but it might actually be more confusing than helpful:

The resulting regex means "either the beginning of the string is
followed by any letter from d to z except g, or there's a g that's
either not before an m, or it is, and followed by the end of the string".

That's because now the | would not only separate the ^ and $ anchors
into becoming alternatives, but the * would cling to the 
which is now allowed to not match at all (because it's a * and not a +).

Also, putting a quantifier (which is what * and + are called) on a
before or after assertion makes no sense and probably leads to an
infinite loop (the regex engine tries to make you proud by matching it
as often as it possibly can. which if the assertion is true, is
infinitely often. it is very diligent, but it does not really think much
about what it does).

Hope that helps
  - Timo


On 17/05/18 12:51, Timo Paulssen wrote:
>
> character classes are fundamentally the wrong thing for "phrases",
> since they describe only a character.
>
> Your current regex (before changing [gm] to ["gm"]) was expressing
> "from the start of the string, there's any amount of characters d
> through z (but neither g nor m) and then the end of the string", which
> can be more easily expressed as "the whole string contains only
> letters d through z (but neither g nor m)".
>
> What you apparently want is "the whole string contains only letters d
> through z, but never the phrase 'gm'", which - in order to get to a
> working regex - we can rephrase as "the whole string contains only
> letters d through z and no occurrence of g is followed by an m". Let's
> turn that into a regex:
>
>     /^ # Require the match to start at the beginning of the
>    # string so nothing can sneak in before that.
>     [  # Everything in this group will be matched a bunch
>    # of times.
>     |  <[d..z]-[g]>  # either anything between d and z, with no
>  # further restrictions, except for g.
>     |  g  # If there's a g, it must not be followed
>  # by an m.
>     ]* # end of the group, allow the things in the group to
>    # occur any amount of times.
>     $/ # Require the match to end at the end of the string,
>    # so nothing at the end can sneak in.
>
> Important things to note here:
>
>   *  (spoken as "do not match before an m") will be fine
> with occurrences at the end of the string, too.
>   * we don't remove the m from the character class any more, we only
> keep the g in there, because m can be in the string without
> restrictions; if there is an m after a g, our regex will already
> have failed before it even reaches the m, and all other cases are
> fine (like dm or fm or hm).
>   * you are allowed to put a | not only between things, but also at
> the very front. This is allowed in the syntax so that you can line
> things up vertically like I did. Think of it as similar to
> allowing a , after the last element in a list, like with [1, 2, 3,
> 4, ]
>
>> hi
>> Match: 「hi」
>> bleh
>> Match: Nil
>> fog
>> Match: 「fog」
>> dm
>> Match: 「dm」
>> fm
>> Match: 「fm」
>> hm
>> Match: 「hm」
>> gm
>> Match: Nil
>> rofl
>> Match: 「rofl」
>> dddg
>> Match: 「dddg」
>> 
>> Match: 「」
>> 
>> Match: 「」
>
> Hope that helps!
>   - Timo



Re: Need match character help

2018-05-16 Thread Todd Chester

Now I am getting silly.

How would I exclude the phrase "gm"?

$ p6 'if "def" ~~ /^<[d..z]-["gm"]>*$/ {say "y"} else {say "n"}'
Potential difficulties:
Quotes are not metacharacters in character classes
at -e:1
--> if "def" ~~ /^<[d..z]-⏏["gm"]>*$/ {say "y"} else {say "n"}
Repeated character (") unexpectedly found in character class
at -e:1
--> if "def" ~~ /^<[d..z]-⏏["gm"]>*$/ {say "y"} else {say "n"}


Re: Need match character help

2018-05-16 Thread Todd Chester
On Wed, May 16, 2018 at 9:05 PM, Todd Chester > 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


Re: Need match character help

2018-05-16 Thread Brandon Allbery
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


On Wed, May 16, 2018 at 9:05 PM, Todd Chester  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'
>



-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Need match character help

2018-05-16 Thread Todd Chester



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'


Re: Need match character help

2018-05-16 Thread Timo Paulssen
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]>/;


Re: Need match character help

2018-05-15 Thread ToddAndMargo

On 05/15/2018 07:05 AM, Timo Paulssen wrote:

On 15/05/18 13:49, ToddAndMargo wrote:

Hi All,

This should be a "no".  What am I doing wrong?

$ perl6 -e 'my $x="rd"; if $x~~/<[rc]+[a]+[b]+[.]>/ {say
"yes"}else{say "no"}'
yes


Many thanks,
-T


what you've put in your regex here is a character class combined of four
individual ones "added together";

it matches a single letter that is either an "r", a "c", an "a", a "b",
or a ".". Character classes always match only a single character, if you
want it to match more, you will have to use a quantifier, like "+", "*",
or "**". Since your regex is not anchored, it will accept any of those
characters in any spot, so strings like "hello a" will match, too.

It seems like what you want is actually this:

/rc | a | b | "."/

which matches if either "rc", "a", "b" or "." exist somewhere in the string.

If you want to accept only if the full string is "rc", "a", "b" or ".",
you'll have to put anchors in the front and back, and put brackets
around the inner part, so that the ^ and $ refer to the whole
alternation, not just the ^ to the first variant and $ to the last variant.




Thank you!


Re: Need match character help

2018-05-15 Thread ToddAndMargo

On 05/15/2018 07:06 AM, Timo Paulssen wrote:

On 15/05/18 14:03, ToddAndMargo wrote:

On 05/15/2018 04:49 AM, ToddAndMargo wrote:

Hi All,

This should be a "no".  What am I doing wrong?

$ perl6 -e 'my $x="rd"; if $x~~/<[rc]+[a]+[b]+[.]>/ {say
"yes"}else{say "no"}'
yes


Many thanks,
-T


And how do I turn this into a yes.  I am look for
any instance of d through z

$ perl6 -e 'my $x="f"; if $x~~/<[d.z]>/ {say "yes"}else{say "no"}'
no


The syntax you're looking for is <[d..z]> rather than <[d.z]>. <[d.z]>
is a character class that will match a d, a "." or a z, where as
<[d..z]> is a character class that matches anything in the range of d to z.



Thank you!

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


Re: Need match character help

2018-05-15 Thread Timo Paulssen
On 15/05/18 14:03, ToddAndMargo wrote:
> On 05/15/2018 04:49 AM, ToddAndMargo wrote:
>> Hi All,
>>
>> This should be a "no".  What am I doing wrong?
>>
>> $ perl6 -e 'my $x="rd"; if $x~~/<[rc]+[a]+[b]+[.]>/ {say
>> "yes"}else{say "no"}'
>> yes
>>
>>
>> Many thanks,
>> -T
>
> And how do I turn this into a yes.  I am look for
> any instance of d through z
>
> $ perl6 -e 'my $x="f"; if $x~~/<[d.z]>/ {say "yes"}else{say "no"}'
> no

The syntax you're looking for is <[d..z]> rather than <[d.z]>. <[d.z]>
is a character class that will match a d, a "." or a z, where as
<[d..z]> is a character class that matches anything in the range of d to z.


Re: Need match character help

2018-05-15 Thread Timo Paulssen
On 15/05/18 13:49, ToddAndMargo wrote:
> Hi All,
>
> This should be a "no".  What am I doing wrong?
>
> $ perl6 -e 'my $x="rd"; if $x~~/<[rc]+[a]+[b]+[.]>/ {say
> "yes"}else{say "no"}'
> yes
>
>
> Many thanks,
> -T

what you've put in your regex here is a character class combined of four
individual ones "added together";

it matches a single letter that is either an "r", a "c", an "a", a "b",
or a ".". Character classes always match only a single character, if you
want it to match more, you will have to use a quantifier, like "+", "*",
or "**". Since your regex is not anchored, it will accept any of those
characters in any spot, so strings like "hello a" will match, too.

It seems like what you want is actually this:

/rc | a | b | "."/

which matches if either "rc", "a", "b" or "." exist somewhere in the string.

If you want to accept only if the full string is "rc", "a", "b" or ".",
you'll have to put anchors in the front and back, and put brackets
around the inner part, so that the ^ and $ refer to the whole
alternation, not just the ^ to the first variant and $ to the last variant.


Re: Need match character help

2018-05-15 Thread ToddAndMargo

On 05/15/2018 04:49 AM, ToddAndMargo wrote:

Hi All,

This should be a "no".  What am I doing wrong?

$ perl6 -e 'my $x="rd"; if $x~~/<[rc]+[a]+[b]+[.]>/ {say "yes"}else{say 
"no"}'

yes


Many thanks,
-T


And how do I turn this into a yes.  I am look for
any instance of d through z

$ perl6 -e 'my $x="f"; if $x~~/<[d.z]>/ {say "yes"}else{say "no"}'
no