Re: Need regex ^? help

2024-05-06 Thread ToddAndMargo via perl6-users

This is what I have so far.

my $x="  1.2.3.4:12345   "; $x = $x.trim; $x~~s/(.*'.') 
.*/$0$(Q[0/24])/; say "<$x>";

<1.2.3.0/24>

It works. Is there a way to petty it up with ^ and $   ?




Re: Need regex ^? help

2024-04-29 Thread ToddAndMargo via perl6-users

On 4/29/24 17:57, Patrick R. Michaud wrote:

Perhaps not really what you're intending, but here's how I'd start:

 $ raku -e 'my $x="1.2.3.4"; $x ~~ s!\d+$!0/24!; say $x;'
 1.2.3.0/24

The pattern part of the substitution matches all of the digits at the end of the string 
(\d+$), then replaces them with the string "0/24".  Everything prior to those 
digits is left alone.

On Mon, Apr 29, 2024 at 05:45:49PM -0700, ToddAndMargo via perl6-users wrote:

On 4/29/24 17:42, ToddAndMargo via perl6-users wrote:

Hi All,

I thought I understood ^ and ? used in a regex'es,
but I don't.

^ means from the beginning and ? from the end.


I think you mean "$" here instead of "?".

Pm



Oh I did figure it out another way.  I am trying to
get a working example of ^ and $ for my Redex
keeper file


Re: Need regex ^? help

2024-04-29 Thread Patrick R. Michaud
Perhaps not really what you're intending, but here's how I'd start:

$ raku -e 'my $x="1.2.3.4"; $x ~~ s!\d+$!0/24!; say $x;'
1.2.3.0/24

The pattern part of the substitution matches all of the digits at the end of 
the string (\d+$), then replaces them with the string "0/24".  Everything prior 
to those digits is left alone.

On Mon, Apr 29, 2024 at 05:45:49PM -0700, ToddAndMargo via perl6-users wrote:
> On 4/29/24 17:42, ToddAndMargo via perl6-users wrote:
> > Hi All,
> > 
> > I thought I understood ^ and ? used in a regex'es,
> > but I don't.
> > 
> > ^ means from the beginning and ? from the end.

I think you mean "$" here instead of "?".

Pm


Re: Need regex ^? help

2024-04-29 Thread ToddAndMargo via perl6-users

On 4/29/24 17:42, ToddAndMargo via perl6-users wrote:

Hi All,

I thought I understood ^ and ? used in a regex'es,
but I don't.

^ means from the beginning and ? from the end.

I am trying to put together an example
of how to use them:

I have

    1.2.3.4

I want
    1.2.3.0/24

So Far I have (not working):

    raku -e 'my $x="1.2.3.4"; $x~~s/ (.*) $(Q[.]) /$0Q[0/24]/; say $x;'

How do I do this with ^ and $  ?

Many thanks,
-T



raku -e 'my $x="1.2.3.4"; $x~~s/ (.*) $(Q[.]) /$0$(Q[0.24])/; say $x;'
1.2.30.244





Re: Need regex help

2018-09-16 Thread ToddAndMargo

On 09/15/2018 07:32 PM, Larry Wall wrote:

On Sat, Sep 15, 2018 at 06:45:33PM -0700, ToddAndMargo wrote:
: Hi All,
:
: I have been doing a bunch with regex's lately.
: I just throw them out based on prior experience
: and they most all work now.  I only sometimes have to
: ask for help.  (The look forward () feature
: is sweet.)
:
: Anyway, I have been using regex switches without
: knowing why. So
:
: What is the difference between
:
: \N

That is a character that is not any of the valid \n characters.

: :\N

That is not a thing.  That is a colon, which causes the previous thing
to not backtrack (if it would), followed by a \N (see above).

: <:\N>

That is not a thing.  In fact, it's a syntax error.

: <<\:N>>

That also is not a thing.  That is a left word boundary <<, followed by
\:, which matches a quote literally because it's backslashed, followed
by an N, which also matches literally, followed by the right word
boundary >>.  As a pattern, it is impossible for the combination to match,
since, while >> can match after a literal N, a << cannot match before a colon.

: And why would I choose one over the other (what
: are they called out for)?

I would never choose any of them, apart from \N.  Where are you getting
this craptastic list from?

Larry



Hi Larry,

Well.  I will have to go through my question with a fine
toothed comb and create a keeper tutorial for what I
come up with.  And in the process, I will no doubt trip
across a lot of stuff I got wrong.

It may be two weeks before I get back -- I have to finish
my company's federal taxes -- but I will get back with whagt I
come up with.

And to answer your question:  I got some of this stuff
from

https://docs.perl6.org/language/regexes#index-entry-regex_%3C%3Aproperty%3E-Unicode_properties

some from context (what I have seen), and

Well, the rest of it from, shall we say pulled out of
my ear.

Into everyone's life a little humiliation must fall.

Thank you for all your help with this.

-T


Re: Need regex help

2018-09-15 Thread Larry Wall
On Sat, Sep 15, 2018 at 06:45:33PM -0700, ToddAndMargo wrote:
: Hi All,
: 
: I have been doing a bunch with regex's lately.
: I just throw them out based on prior experience
: and they most all work now.  I only sometimes have to
: ask for help.  (The look forward () feature
: is sweet.)
: 
: Anyway, I have been using regex switches without
: knowing why. So
: 
: What is the difference between
: 
: \N

That is a character that is not any of the valid \n characters.

: :\N

That is not a thing.  That is a colon, which causes the previous thing
to not backtrack (if it would), followed by a \N (see above).

: <:\N>

That is not a thing.  In fact, it's a syntax error.

: <<\:N>>

That also is not a thing.  That is a left word boundary <<, followed by
\:, which matches a quote literally because it's backslashed, followed
by an N, which also matches literally, followed by the right word
boundary >>.  As a pattern, it is impossible for the combination to match,
since, while >> can match after a literal N, a << cannot match before a colon.

: And why would I choose one over the other (what
: are they called out for)?

I would never choose any of them, apart from \N.  Where are you getting
this craptastic list from?

Larry


Re: need regex help

2018-08-05 Thread ToddAndMargo

On 08/02/2018 09:43 AM, Arthur Ramos Jr. wrote:

This works too:

my $x = "9.0v1"; die "Horribly" if $x =~ /[\p{L}]+/;

Art


Perl 5 by chance (=~)?  Or am I missing something?


Re: need regex help

2018-08-05 Thread Curt Tilmes
On Thu, Aug 2, 2018 at 8:18 AM Timo Paulssen  wrote:

> Is this what you want?
>
> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
> 「12345」
>
> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
> Nil


On Sun, Aug 5, 2018 at 6:41 PM Arthur Ramos Jr. 
wrote:

> my $x = "9.0v1"; die "Horribly" if $x =~ /[\p{L}]+/;
>
>
For that matter, you can also just use plain old unary +  (
https://docs.perl6.org/routine/+#(Operators)_prefix_+)

~$ perl6 -e 'say +"12345"'
12345
~$ perl6 -e 'say +"123a45"'
Cannot convert string to number: trailing characters after number in
'123⏏a45' (indicated by ⏏)
  in block  at -e line 1

~$ perl6 -e 'say +"9.0v1"'
Cannot convert string to number: trailing characters after number in
'9.0⏏v1' (indicated by ⏏)
  in block  at -e line 1

If the string is numeric, you get the number back, otherwise an exception.

Curt


Re: need regex help

2018-08-05 Thread Arthur Ramos Jr.
This works too:

my $x = "9.0v1"; die "Horribly" if $x =~ /[\p{L}]+/;

Art

On Thu, Aug 2, 2018 at 8:18 AM Timo Paulssen  wrote:

> Is this what you want?
>
> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
> 「12345」
>
> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
> Nil
>
> HTH
>   - Timo
>


-- 
==
Arthur Ramos Jr.
207 Wisner Avenue
Middletown, NY  10940
==
"Don't dig in against Bob Gibson, he'll knock you down. He'd knock down his
own grandmother if she dared to challenge him. Don't stare at him, don't
smile at him, don't talk to him. He doesn't like it. If you happen to hit a
home run, don't run too slow, don't run too fast. If you happen to want to
celebrate, get in the tunnel first. And if he hits you, don't charge the
mound, because he's a Gold Glove boxer." ~ Hank Aaron's advice to Dusty
Baker


Re: need regex help

2018-08-03 Thread ToddAndMargo

On 08/03/2018 11:36 AM, Parrot Raiser wrote:

If I've interpreted this
https://docs.perl6.org/language/regexes#Enumerated_character_classes_and_ranges
correctly,

^ is "start of string"
+alnum means "in the alphanumeric set"
-alpha   means "not in the purely alphabetic set"
i.e. <+alnum -alpha> means "alphanumeric but not a letter", i.e 0-9_
+ is "one or more of the preceding set"
$ is "end of string"


Thank you!


Re: need regex help

2018-08-03 Thread ToddAndMargo

On 08/03/2018 11:52 AM, Patrick R. Michaud wrote:

The + essentially indicates that this is a character-class match.  It's to distinguish things from 
<.alpha>, , , <-alpha>, and  (among others).


Thank you!


Re: need regex help

2018-08-03 Thread ToddAndMargo

On 08/03/2018 11:48 AM, Timo Paulssen wrote:

The + is required, perhaps because the first character after the opening
< is supposed to determine exactly what thing it is? Not sure about
that. The + and - is a bit like "start at nothing, add all alnums, then
subtract all alphas". The + after the < > is just to match it any number
of times, but at least once, and the $ at the end, together with the ^
at the start, ensures that every character in the string has to match,
not just any character.

Hope that makes sense
   - Timo


Thank you!


Re: need regex help

2018-08-03 Thread Patrick R. Michaud
The + essentially indicates that this is a character-class match.  It's to 
distinguish things from <.alpha>, , , <-alpha>, and  
(among others).

Pm

On Fri, Aug 03, 2018 at 08:48:24PM +0200, Timo Paulssen wrote:
> The + is required, perhaps because the first character after the opening
> < is supposed to determine exactly what thing it is? Not sure about
> that. The + and - is a bit like "start at nothing, add all alnums, then
> subtract all alphas". The + after the < > is just to match it any number
> of times, but at least once, and the $ at the end, together with the ^
> at the start, ensures that every character in the string has to match,
> not just any character.
> 
> Hope that makes sense
>   - Timo
> 
> 
> On 03/08/18 20:04, ToddAndMargo wrote:
> > On 08/02/2018 05:18 AM, Timo Paulssen wrote:
> >> Is this what you want?
> >>
> >> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
> >> 「12345」
> >>
> >> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
> >> Nil
> >>
> >> HTH
> >>    - Timo
> >>
> >
> > What does the following do?
> >
> >  +alnum   (why does it need the "+"?)
> >  -alpha   (I presume "-" means negate?)
> >  +$
> >
> > Many thanks,
> > -T


Re: need regex help

2018-08-03 Thread Timo Paulssen
The + is required, perhaps because the first character after the opening
< is supposed to determine exactly what thing it is? Not sure about
that. The + and - is a bit like "start at nothing, add all alnums, then
subtract all alphas". The + after the < > is just to match it any number
of times, but at least once, and the $ at the end, together with the ^
at the start, ensures that every character in the string has to match,
not just any character.

Hope that makes sense
  - Timo


On 03/08/18 20:04, ToddAndMargo wrote:
> On 08/02/2018 05:18 AM, Timo Paulssen wrote:
>> Is this what you want?
>>
>> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
>> 「12345」
>>
>> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
>> Nil
>>
>> HTH
>>    - Timo
>>
>
> What does the following do?
>
>  +alnum   (why does it need the "+"?)
>  -alpha   (I presume "-" means negate?)
>  +$
>
> Many thanks,
> -T


Re: need regex help

2018-08-03 Thread Brandon Allbery
That document also says that _ is considered a letter (that is, is matched
by :
https://docs.perl6.org/language/regexes#Predefined_Character_Classes), so
that's the same thing as . I observed that earlier as well.

On Fri, Aug 3, 2018 at 2:37 PM Parrot Raiser <1parr...@gmail.com> wrote:

> If I've interpreted this
>
> https://docs.perl6.org/language/regexes#Enumerated_character_classes_and_ranges
> correctly,
>
> ^ is "start of string"
> +alnum means "in the alphanumeric set"
> -alpha   means "not in the purely alphabetic set"
> i.e. <+alnum -alpha> means "alphanumeric but not a letter", i.e 0-9_
> + is "one or more of the preceding set"
> $ is "end of string"
>
> On 8/3/18, ToddAndMargo  wrote:
> > On 08/02/2018 05:18 AM, Timo Paulssen wrote:
> >> Is this what you want?
> >>
> >> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
> >> 「12345」
> >>
> >> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
> >> Nil
> >>
> >> HTH
> >>- Timo
> >>
> >
> > What does the following do?
> >
> >   +alnum   (why does it need the "+"?)
> >   -alpha   (I presume "-" means negate?)
> >   +$
> >
> > Many thanks,
> > -T
> >
>


-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: need regex help

2018-08-03 Thread Parrot Raiser
If I've interpreted this
https://docs.perl6.org/language/regexes#Enumerated_character_classes_and_ranges
correctly,

^ is "start of string"
+alnum means "in the alphanumeric set"
-alpha   means "not in the purely alphabetic set"
i.e. <+alnum -alpha> means "alphanumeric but not a letter", i.e 0-9_
+ is "one or more of the preceding set"
$ is "end of string"

On 8/3/18, ToddAndMargo  wrote:
> On 08/02/2018 05:18 AM, Timo Paulssen wrote:
>> Is this what you want?
>>
>> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
>> 「12345」
>>
>> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
>> Nil
>>
>> HTH
>>    - Timo
>>
>
> What does the following do?
>
>   +alnum   (why does it need the "+"?)
>   -alpha   (I presume "-" means negate?)
>   +$
>
> Many thanks,
> -T
>


Re: need regex help

2018-08-03 Thread ToddAndMargo

On 08/02/2018 05:18 AM, Timo Paulssen wrote:

Is this what you want?

perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
「12345」

perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
Nil

HTH
   - Timo



What does the following do?

 +alnum   (why does it need the "+"?)
 -alpha   (I presume "-" means negate?)
 +$

Many thanks,
-T


Re: need regex help

2018-08-03 Thread ToddAndMargo

On 08/02/2018 05:18 AM, Timo Paulssen wrote:

Is this what you want?

perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
「12345」

perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
Nil

HTH
   - Timo



A piece of art.  Thank you!


Re: need regex help

2018-08-02 Thread Timo Paulssen
Is this what you want?

perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
「12345」

perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
Nil

HTH
  - Timo


Re: need regex help

2018-08-02 Thread Laurent Rosenfeld via perl6-users
Set operations seem to be unsupported on predefined character classes (or
subrules). (Or, if they are supported, I don't know what the right syntax
might be.)

Set operations seem to work properly, though, with escaped character
classes. For example:

perl6 -e 'my $x = "9.0v1"; say so $x ~~ /<[\w] - [\d_]>;/'

or with Unicode properties' short names:

perl6 -e 'my $x = "9.0v1"; say  $x ~~ /<[\w] - :N>/;'
or, to find digits instead of letters:
perl6 -e 'my $x = "9.0v1"; say  $x ~~ /<[\w] - :L>/;'
or this:
perl6 -e 'my $x = "9.0v1"; say  $x ~~ /<[\w] - [:L_]>/;'

But I agree that  using //  is probably better. For example:

perl6 -e 'my $x = "9.0v1"; say  $x ~~ /^+$/;

or possibly:
perl6 -e 'my $x = "9.0v1'; say  $x !~~ /<-[\d]>/;'

Best,
Laurent.

2018-08-02 7:00 GMT+02:00 Brandon Allbery :

> Set operations have to be inside the <>. You want something like:
> /<[alnum-alpha]>/.
>
> That said, this would be the same as //, I think? Please describe
> in words what you intended with that regex. (I suspect /<[alpha]>/ is what
> you really want, based on your earlier statement.)
>
> On Thu, Aug 2, 2018 at 12:57 AM ToddAndMargo 
> wrote:
>
>> Hi All,
>>
>> If there are any letter in the string, I want it to fail
>>
>>
>>
>> $ p6 'my $x="9.0v1"; if $x~~/<+alnum>-[]>/ {say "Y";}'
>> ===SORRY!===
>> Unrecognized regex metacharacter - (must be quoted to match literally)
>> at -e:1
>> --> my $x="9.0v1"; if $x~~/<+alnum>⏏-[]>/ {say "Y";}
>> Unable to parse regex; couldn't find final '/'
>> at -e:1
>> --> my $x="9.0v1"; if $x~~/<+alnum>-⏏[]>/ {say "Y";}
>>
>>
>>
>> What am I doing wrong?
>>
>> Many thanks,
>> -T
>>
>
>
> --
> brandon s allbery kf8nh
> allber...@gmail.com
>


Re: need regex help

2018-08-02 Thread Paul Procacci
\d and  both match Unicode characters as well.
If that's not the intention then it's best to be explicit.

die("Horribly") unless "9.b1" ~~ / <[0-9]+> % '.' /;

Typing from my phone so unable to test the above***


On Thu, Aug 2, 2018, 12:56 AM ToddAndMargo  wrote:

> Hi All,
>
> If there are any letter in the string, I want it to fail
>
>
>
> $ p6 'my $x="9.0v1"; if $x~~/<+alnum>-[]>/ {say "Y";}'
> ===SORRY!===
> Unrecognized regex metacharacter - (must be quoted to match literally)
> at -e:1
> --> my $x="9.0v1"; if $x~~/<+alnum>⏏-[]>/ {say "Y";}
> Unable to parse regex; couldn't find final '/'
> at -e:1
> --> my $x="9.0v1"; if $x~~/<+alnum>-⏏[]>/ {say "Y";}
>
>
>
> What am I doing wrong?
>
> Many thanks,
> -T
>


Re: need regex help

2018-08-01 Thread ToddAndMargo

On 08/01/2018 10:00 PM, Brandon Allbery wrote:
Set operations have to be inside the <>. You want something like: 
/<[alnum-alpha]>/.


That said, this would be the same as //, I think? Please describe 
in words what you intended with that regex. (I suspect /<[alpha]>/ is 
what you really want, based on your earlier statement.)


Poop!

p6 'my $x="9.01"; if not $x~~/<[alpha-alnum]>/ {say "Y";}else{say "N";}'
===SORRY!=== Error while compiling -e
Unsupported use of - as character range; in Perl 6 please use .. for 
range, for explicit - in character class, escape it or place it as the 
first or last thing

at -e:1
--> my $x="9.01"; if not $x~~/<[alpha-⏏alnum]>/ {say "Y";}else{say "N";}


This is my workaround:

$ p6 'my $x="9.b01"; if not $x~~// && $x~~// {say 
"Y";}else{say "N";}'

N

$ p6 'my $x="9.01"; if not $x~~// && $x~~// {say 
"Y";}else{say "N";}'

Y


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


Re: need regex help

2018-08-01 Thread Brandon Allbery
Set operations have to be inside the <>. You want something like:
/<[alnum-alpha]>/.

That said, this would be the same as //, I think? Please describe in
words what you intended with that regex. (I suspect /<[alpha]>/ is what you
really want, based on your earlier statement.)

On Thu, Aug 2, 2018 at 12:57 AM ToddAndMargo  wrote:

> Hi All,
>
> If there are any letter in the string, I want it to fail
>
>
>
> $ p6 'my $x="9.0v1"; if $x~~/<+alnum>-[]>/ {say "Y";}'
> ===SORRY!===
> Unrecognized regex metacharacter - (must be quoted to match literally)
> at -e:1
> --> my $x="9.0v1"; if $x~~/<+alnum>⏏-[]>/ {say "Y";}
> Unable to parse regex; couldn't find final '/'
> at -e:1
> --> my $x="9.0v1"; if $x~~/<+alnum>-⏏[]>/ {say "Y";}
>
>
>
> What am I doing wrong?
>
> Many thanks,
> -T
>


-- 
brandon s allbery kf8nh
allber...@gmail.com