Re: case insensitive "contains"?

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:53 PM, Trey Harris wrote:

And my response to his response that also was unintentionally off-list.



I got it.  I will probably be writing it down later today
in my documents.

My failing was thinking rx was some kind of command
I had not seen before.  As soon as you showed me it
was of a dynamic way of salting the inside of a regex
with commands, the lights when off.

Excellent write up by the way.  Thank you!


Re: case insensitive "contains"?

2018-09-11 Thread Trey Harris
And my response to his response that also was unintentionally off-list.

(Todd, if you don't mind resending your last private response—since your
other response was quoted below—in reply to this, please do.)

On Mon, Sep 10, 2018 at 22:00 ToddAndMargo  wrote:
> So you get to iteratively pick what the regex will be.
> I can see where this would be very powerful. Thank you!
>
> Also, really a bad idea to use in documentation
> as it "presumes" that the reader is very advanced in
> his knowledge of regex's. In which case he would
> not need to read the documentation anyway.

Pardon? I don't follow. "Really a bad idea to use" what?

Personally, I get rather annoyed when I have to sift through Yet Another
Introduction to Regexes just in order to find out how to use regexes in a
particular language or library. The documentation for a regex library
shouldn't explain regexes, if that's what you're saying. Most programmers
will be coming to any new language already knowing regexes of some sort.

I don't see what's "very advanced in... knowledge of regex[es]". Those
examples don't even use quantifiers; they're just fixed text matches with
case-insensitivity. If you find that "advanced", you should do one of the
many excellent regex tutorials available in whatever languages or
programmable editors you already know—trying to learn regexes and a new
language simultaneously will be a bit overwhelming, as regexes are a
language and practice unto themselves.

Perl 6's regex syntax is rather different from other languages' (a bit
amusingly, since in the meantime other modern languages have mostly
coalesced around adopting something close to Perl 5's), but you'll be much
better-equipped to understand them in Perl 6 if you understand them in
general first.


On Tue, Sep 11, 2018 at 18:49 Trey Harris  wrote:

> Oops— I sent the following yesterday and it somehow didn't go to the list:
>
> On Mon, Sep 10, 2018 at 19:02 ToddAndMargo  wrote:
>
>> Question, what the heck is
>>
>>   my $rx1 = rx:i/a/;
>>
>> Are they talking over beginner's heads again?
>>
>
> In the sense of "beginners to Perl", perhaps, since "rx" is familiar to
> Perl 5 programmers.
>
> Though if you search docs.perl6.org for "rx" you'll see a choice in the
> pop-down, "rx (quote)", which leads to:
>
> https://docs.perl6.org/language/regexes#index-entry-quote_%2F_%2F-quote_rx-quote_m-Lexical_conventions
>  and
> that says:
>
> ```
>
> Perl 6 has special syntax for writing regexes:
>
> m/abc/; # a regex that is immediately matched against $_
>
> rx/abc/;# a Regex object; allow adverbs to be used before regex
>
> /abc/;  # a Regex object; shorthand version of 'rx/ /' operator
> ```
>
> That entire section of the documentation is worth reading as it describes
> everything discussed in this thread.
>
> But in case it isn't clear, it just means that if you do
>
> my $result = "Juli 2018" ~~ m:i/jul/;
>
> then you'll get a match containing "Jul" as a result.
>
> It so happens in this case, when using ~~ against a literal like above,
> m// and rx// are pretty much interchangeable.
>
> But you could also do:
>
> my $pattern = rx:i/jul/;
> my $result = "Juli 2018" ~~ $pattern;
>
> and get the same result.
>
> If you tried to do
>
>my $pattern = m:i/jul/;
>
> You'll get an exception unless the $_ topic variable happens to contain a
> thing that can be regex-matched (like a string). The `m` explicitly causes
> the match to happen immediately.
>


Re: case insensitive "contains"?

2018-09-11 Thread Trey Harris
Oops— I sent the following yesterday and it somehow didn't go to the list:

On Mon, Sep 10, 2018 at 19:02 ToddAndMargo  wrote:

> Question, what the heck is
>
>   my $rx1 = rx:i/a/;
>
> Are they talking over beginner's heads again?
>

In the sense of "beginners to Perl", perhaps, since "rx" is familiar to
Perl 5 programmers.

Though if you search docs.perl6.org for "rx" you'll see a choice in the
pop-down, "rx (quote)", which leads to:
https://docs.perl6.org/language/regexes#index-entry-quote_%2F_%2F-quote_rx-quote_m-Lexical_conventions
and
that says:

```

Perl 6 has special syntax for writing regexes:

m/abc/; # a regex that is immediately matched against $_

rx/abc/;# a Regex object; allow adverbs to be used before regex

/abc/;  # a Regex object; shorthand version of 'rx/ /' operator
```

That entire section of the documentation is worth reading as it describes
everything discussed in this thread.

But in case it isn't clear, it just means that if you do

my $result = "Juli 2018" ~~ m:i/jul/;

then you'll get a match containing "Jul" as a result.

It so happens in this case, when using ~~ against a literal like above, m//
and rx// are pretty much interchangeable.

But you could also do:

my $pattern = rx:i/jul/;
my $result = "Juli 2018" ~~ $pattern;

and get the same result.

If you tried to do

   my $pattern = m:i/jul/;

You'll get an exception unless the $_ topic variable happens to contain a
thing that can be regex-matched (like a string). The `m` explicitly causes
the match to happen immediately.


Re: case insensitive "contains"?

2018-09-10 Thread ToddAndMargo

On 09/10/2018 08:15 AM, Ralph Mellor wrote:

Hi Todd,

What are the rules for what goes inside and what goes outside?

Also, do y have a link to what the various ":x" commands are that I
can use?


See https://docs.perl6.org/language/regexes#Adverbs

The first section explains the two types of "adverb".
"regex adverbs" like `:i` can go either outside or inside.
"match adverbs" like `:g` can only go outside.

The sections that follow the intro cover all the regex and match adverbs.

I generally prefer to use "contains", "starts-with", and "ends-with"
when
the string is full of trash that regex needs to escape.

Me too because it runs much quicker and reads a bit more clearly imo.

--
raiph


Thank you!

I think is it a right of passage for a perl programmer
when he finally understands regex's


Re: case insensitive "contains"?

2018-09-10 Thread ToddAndMargo

On 09/10/2018 08:36 AM, Laurent Rosenfeld via perl6-users wrote:

Yes, copy and paste error on the last code snippet.

say "Yes" if "2018 xJul 7" ~~ m/j :i ul/;

Cheers,
Laurent.


Now that is down right cleaver!  I can change my mind
as I go.  Thank you!


Re: case insensitive "contains"?

2018-09-10 Thread ToddAndMargo

Hi Laurent,

Thank you!  Another weapon in my tool box!

Question:  this confused me when I first look at it.  I am use to
the ":x" command being outside the first "/".  For instance
  s:g/

What are the rules for what goes inside and what goes outside?

Also, do y have a link to what the various ":x" commands are
that I can use?

I generally prefer to use "contains", "starts-with", and
"ends-with" when the string is full of trash that regex needs
to escape.  For example:

if $Line.contains( 'HWiNFO ' &
'
Installer' ) {


Many thanks,
-T


On 09/10/2018 04:54 AM, Laurent Rosenfeld via perl6-users wrote:

Hi Todd,

you may use:

say "Yes" if "2018 xJul 7" ~~ /:i jul/;

or:

say "Yes" if "2018 xJul 7" ~~ m:i/jul/;

In the second case, the adverb will apply to the whole pattern. In the 
first case, it will start to apply from the point where the adverb is. 
In this specific example, those two code samples will be equivalent 
since the adverb is at the beginning of the pattern. But it would make a 
difference if the adverb is somewhere else within the pattern. For 
example, this would fail:


say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;

because the ignore case adverb would apply only on the 'ul' characters 
of the pattern, but not on the 'j'.


More on adverbs in regexes: https://docs.perl6.org/language/regexes#Adverbs

Cheers,
Laurent.


Le lun. 10 sept. 2018 à 00:00, ToddAndMargo > a écrit :


On 09/08/2018 12:23 PM, Laurent Rosenfeld via perl6-users wrote:
 > Using the fc method is certainly a good way to do case insensitive
 > string comparisons, but you may at this point also use a regex
with the
 > :i (ignore case) adverb.
 >
 >  > if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
 > Yes
 >



Thank you!  I will be copying down the section on adverbs
into my documentation.

Question, what the heck is

 my $rx1 = rx:i/a/;

Are they talking over beginner's heads again?


Re: case insensitive "contains"?

2018-09-10 Thread Laurent Rosenfeld via perl6-users
Yes, copy and paste error on the last code snippet.

say "Yes" if "2018 xJul 7" ~~ m/j :i ul/;

Cheers,
Laurent.


Le lun. 10 sept. 2018 à 16:54, yary  a écrit :

> > say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;
> you mean
>
> say "Yes" if "2018 xJul 7" ~~ m/j :i ul/;
>
> m/.../ - not m:i at the start!
>
> -y
>
> On Mon, Sep 10, 2018 at 4:54 AM, Laurent Rosenfeld via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hi Todd,
>>
>> you may use:
>>
>> say "Yes" if "2018 xJul 7" ~~ /:i jul/;
>>
>> or:
>>
>> say "Yes" if "2018 xJul 7" ~~ m:i/jul/;
>>
>> In the second case, the adverb will apply to the whole pattern. In the
>> first case, it will start to apply from the point where the adverb is. In
>> this specific example, those two code samples will be equivalent since the
>> adverb is at the beginning of the pattern. But it would make a difference
>> if the adverb is somewhere else within the pattern. For example, this would
>> fail:
>>
>> say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;
>>
>> because the ignore case adverb would apply only on the 'ul' characters of
>> the pattern, but not on the 'j'.
>>
>> More on adverbs in regexes:
>> https://docs.perl6.org/language/regexes#Adverbs
>>
>> Cheers,
>> Laurent.
>>
>>
>> Le lun. 10 sept. 2018 à 00:00, ToddAndMargo  a
>> écrit :
>>
>>> On 09/08/2018 12:23 PM, Laurent Rosenfeld via perl6-users wrote:
>>> > Using the fc method is certainly a good way to do case insensitive
>>> > string comparisons, but you may at this point also use a regex with
>>> the
>>> > :i (ignore case) adverb.
>>> >
>>> >  > if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
>>> > Yes
>>> >
>>>
>>> Hi Laurent,
>>>
>>> Thank you!  Another weapon in my tool box!
>>>
>>> Question:  this confused me when I first look at it.  I am use to
>>> the ":x" command being outside the first "/".  For instance
>>>  s:g/
>>>
>>> What are the rules for what goes inside and what goes outside?
>>>
>>> Also, do y have a link to what the various ":x" commands are
>>> that I can use?
>>>
>>> I generally prefer to use "contains", "starts-with", and
>>> "ends-with" when the string is full of trash that regex needs
>>> to escape.  For example:
>>>
>>> if $Line.contains( 'HWiNFO ' & '
>>> Installer' ) {
>>>
>>>
>>> Many thanks,
>>> -T
>>>
>>>
>>> --
>>> ~
>>> When we ask for advice, we are usually looking for an accomplice.
>>> --  Charles Varlet de La Grange
>>> ~
>>>
>>
>


Re: case insensitive "contains"?

2018-09-10 Thread Ralph Mellor
Hi Todd,


> What are the rules for what goes inside and what goes outside?
>
Also, do y have a link to what the various ":x" commands are that I can use?
>

See https://docs.perl6.org/language/regexes#Adverbs

The first section explains the two types of "adverb".
"regex adverbs" like `:i` can go either outside or inside.
"match adverbs" like `:g` can only go outside.

The sections that follow the intro cover all the regex and match adverbs.

I generally prefer to use "contains", "starts-with", and "ends-with" when
> the string is full of trash that regex needs to escape.


Me too because it runs much quicker and reads a bit more clearly imo.

--
raiph


Re: case insensitive "contains"?

2018-09-10 Thread yary
> say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;
you mean

say "Yes" if "2018 xJul 7" ~~ m/j :i ul/;

m/.../ - not m:i at the start!

-y

On Mon, Sep 10, 2018 at 4:54 AM, Laurent Rosenfeld via perl6-users <
perl6-users@perl.org> wrote:

> Hi Todd,
>
> you may use:
>
> say "Yes" if "2018 xJul 7" ~~ /:i jul/;
>
> or:
>
> say "Yes" if "2018 xJul 7" ~~ m:i/jul/;
>
> In the second case, the adverb will apply to the whole pattern. In the
> first case, it will start to apply from the point where the adverb is. In
> this specific example, those two code samples will be equivalent since the
> adverb is at the beginning of the pattern. But it would make a difference
> if the adverb is somewhere else within the pattern. For example, this would
> fail:
>
> say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;
>
> because the ignore case adverb would apply only on the 'ul' characters of
> the pattern, but not on the 'j'.
>
> More on adverbs in regexes: https://docs.perl6.org/
> language/regexes#Adverbs
>
> Cheers,
> Laurent.
>
>
> Le lun. 10 sept. 2018 à 00:00, ToddAndMargo  a
> écrit :
>
>> On 09/08/2018 12:23 PM, Laurent Rosenfeld via perl6-users wrote:
>> > Using the fc method is certainly a good way to do case insensitive
>> > string comparisons, but you may at this point also use a regex with the
>> > :i (ignore case) adverb.
>> >
>> >  > if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
>> > Yes
>> >
>>
>> Hi Laurent,
>>
>> Thank you!  Another weapon in my tool box!
>>
>> Question:  this confused me when I first look at it.  I am use to
>> the ":x" command being outside the first "/".  For instance
>>  s:g/
>>
>> What are the rules for what goes inside and what goes outside?
>>
>> Also, do y have a link to what the various ":x" commands are
>> that I can use?
>>
>> I generally prefer to use "contains", "starts-with", and
>> "ends-with" when the string is full of trash that regex needs
>> to escape.  For example:
>>
>> if $Line.contains( 'HWiNFO ' & '
>> Installer' ) {
>>
>>
>> Many thanks,
>> -T
>>
>>
>> --
>> ~
>> When we ask for advice, we are usually looking for an accomplice.
>> --  Charles Varlet de La Grange
>> ~
>>
>


Re: case insensitive "contains"?

2018-09-10 Thread Laurent Rosenfeld via perl6-users
Hi Todd,

you may use:

say "Yes" if "2018 xJul 7" ~~ /:i jul/;

or:

say "Yes" if "2018 xJul 7" ~~ m:i/jul/;

In the second case, the adverb will apply to the whole pattern. In the
first case, it will start to apply from the point where the adverb is. In
this specific example, those two code samples will be equivalent since the
adverb is at the beginning of the pattern. But it would make a difference
if the adverb is somewhere else within the pattern. For example, this would
fail:

say "Yes" if "2018 xJul 7" ~~ m:i/j :i ul/;

because the ignore case adverb would apply only on the 'ul' characters of
the pattern, but not on the 'j'.

More on adverbs in regexes: https://docs.perl6.org/language/regexes#Adverbs

Cheers,
Laurent.


Le lun. 10 sept. 2018 à 00:00, ToddAndMargo  a
écrit :

> On 09/08/2018 12:23 PM, Laurent Rosenfeld via perl6-users wrote:
> > Using the fc method is certainly a good way to do case insensitive
> > string comparisons, but you may at this point also use a regex with the
> > :i (ignore case) adverb.
> >
> >  > if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
> > Yes
> >
>
> Hi Laurent,
>
> Thank you!  Another weapon in my tool box!
>
> Question:  this confused me when I first look at it.  I am use to
> the ":x" command being outside the first "/".  For instance
>  s:g/
>
> What are the rules for what goes inside and what goes outside?
>
> Also, do y have a link to what the various ":x" commands are
> that I can use?
>
> I generally prefer to use "contains", "starts-with", and
> "ends-with" when the string is full of trash that regex needs
> to escape.  For example:
>
> if $Line.contains( 'HWiNFO ' & '
> Installer' ) {
>
>
> Many thanks,
> -T
>
>
> --
> ~
> When we ask for advice, we are usually looking for an accomplice.
> --  Charles Varlet de La Grange
> ~
>


Re: case insensitive "contains"?

2018-09-09 Thread ToddAndMargo

On 09/08/2018 12:23 PM, Laurent Rosenfeld via perl6-users wrote:
Using the fc method is certainly a good way to do case insensitive 
string comparisons, but you may at this point also use a regex with the 
:i (ignore case) adverb.


 > if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
Yes



Hi Laurent,

Thank you!  Another weapon in my tool box!

Question:  this confused me when I first look at it.  I am use to
the ":x" command being outside the first "/".  For instance
s:g/

What are the rules for what goes inside and what goes outside?

Also, do y have a link to what the various ":x" commands are
that I can use?

I generally prefer to use "contains", "starts-with", and
"ends-with" when the string is full of trash that regex needs
to escape.  For example:

if $Line.contains( 'HWiNFO ' & ' 
Installer' ) {



Many thanks,
-T


--
~
When we ask for advice, we are usually looking for an accomplice.
   --  Charles Varlet de La Grange
~


Re: case insensitive "contains"?

2018-09-08 Thread Laurent Rosenfeld via perl6-users
Using the fc method is certainly a good way to do case insensitive string
comparisons, but you may at this point also use a regex with the :i (ignore
case) adverb.

> if "2018 xJul 7" ~~ /:i jul/ {say "Yes";}
Yes


Le sam. 8 sept. 2018 à 00:56, ToddAndMargo  a écrit :

> On 09/07/2018 03:49 PM, ToddAndMargo wrote:
> > Hi All,
> >
> > How do I use "contains" without regard to case?
> >
> > $ p6 'if "2018 Jul 7".contains( "jul", 3 ) {say "Yes";}'
> >
> >
> > Many thanks,
> > -T
>
>
> The chat line helped me figure it out:
>
> $ p6 'if "2018 Jul 7".fc.contains( "jul".fc ) {say "Yes";}'
> Yes
>
> $ p6 'if "2018 xJul 7".fc.contains( "jul".fc ) {say "Yes";}'
> Yes
>
> p6 'if "2018 xul 7".fc.contains( "jul".fc ) {say "Yes";}'
> 
>


Re: case insensitive "contains"?

2018-09-07 Thread ToddAndMargo

On 09/07/2018 03:49 PM, ToddAndMargo wrote:

Hi All,

How do I use "contains" without regard to case?

$ p6 'if "2018 Jul 7".contains( "jul", 3 ) {say "Yes";}'


Many thanks,
-T



The chat line helped me figure it out:

$ p6 'if "2018 Jul 7".fc.contains( "jul".fc ) {say "Yes";}'
Yes

$ p6 'if "2018 xJul 7".fc.contains( "jul".fc ) {say "Yes";}'
Yes

p6 'if "2018 xul 7".fc.contains( "jul".fc ) {say "Yes";}'



case insensitive "contains"?

2018-09-07 Thread ToddAndMargo

Hi All,

How do I use "contains" without regard to case?

$ p6 'if "2018 Jul 7".contains( "jul", 3 ) {say "Yes";}'


Many thanks,
-T