^^  has the regex meaning "start-of-line"
$$  has the regex meaning "end-of-line"

Compare to:

^  has the regex meaning "start-of-string"
$  has the regex meaning "end-of-string"

If you're analyzing input linewise (for example using a one-liner with `-ne` or 
`-pe` flags), 
then start-of-line equals start-of-string, and end-of-line equals end-of-string.

HTH, Bill.



> On Oct 25, 2025, at 16:09, ToddAndMargo via perl6-users 
> <[email protected]> wrote:
> 
>>> 
>>> On Oct 25, 2025, at 05:19, ToddAndMargo via perl6-users <perl6- 
>>> [email protected] <mailto:[email protected]>> wrote:
>>> 
>>> Hi All,
>>> 
>>> What am I doing wrong here:
>>> 
>>> [2] > my Str $x = "1.40.564"; $x~~s:i/ '.' $$ .* //; print "$x\n";
>>> 1.40.564
>>> 
>>> I am after "1.40"
>>> 
>>> This is my work around, but I'd really like to know
>>> how to do it right:
>>> 
>>> my Str $x = "1.40.564"; $x~~m:i/ ( .*? '.') (.*? ) '.' /; print "$0$1\n";
>>> 1.40
>>> 
>>> Your in confusion,
>>> -T
> 
> On 10/25/25 8:06 AM, William Michels wrote:
> > [0] > my $x = "1.40.564"; $x = $x ~~ m/ ^  <-[.]>+ "." <-[.]>+ /; say ~$x;
> > 1.40
> > [0] > my $x = "1.40.564"; $x = $x.match(/ ^  <-[.]>+ "." <-[.]>+ /); say
> > ~$x;
> > 1.40
> >
> > #OR
> >
> > [1] > my $x = "1.40.564"; $x = S/ "." <-[.]>+ $ // given $x; say $x;
> > 1.40
> > [1] > my $x = "1.40.564"; $x = $x.subst(/ "." <-[.]>+ $  /, "" ); say $x;
> > 1.40
> >
> > One issue with your code was failing to create a `<-[.]>` enumerated
> > character class.
> > This (negated) `<-[.]>` class consists of all characters other than `.`
> > dot (i.e. period).
> >
> > Now read the regexes above:
> >      1. The first two matching expressions look for "start-of-string,
> > non-dot characters, a dot, then more non-dot characters".
> >      2. The last two substitution expressions look for "a dot, non-dot
> > characters, then end-of-string".
> >
> > HTH, Bill.
> >
> 
> Hi Bill,
> 
> Thank you.  It does!
> 
> It also tells me that the easiest way way actually the "m'
> work around I came up with and that I have no understanding
> of $$ and ^^ in regexes.  So I have some work to do.
> 
> -T

Reply via email to