develooper Front page | perl.perl6.users | Postings from October 2022

regex: how to I pick out items in the middle?

Thread Next
From:
ToddAndMargo via perl6-users
Date:
October 30, 2022 01:46
Subject:
regex: how to I pick out items in the middle?
Message ID:
6fb43fbd-5861-2b83-7b04-48022beccf4a@zoho.com
Hi All,

With a regex, how do I pick out items in the middle of the string?  Two 
from the beginning or two from the end?


4] > my Str $y="xxxxxx"; $y ~~ s/ $([.*-2]) "x"/Q/; print $y ~ "\n"

===SORRY!=== Error while compiling:
Malformed postfix call
------> my Str $y="xxxxxx"; $y ~~ s/ $([.*⏏-2]) "x"/Q/; print $y ~ "\n"



I am trying to do something like this:

[0] > my Str $x="1\n2\n3\n4\n5\n"
1
2
3
4
5

[1] > print $x.lines[*-2] ~ "\n"
4



Many thanks,
-T


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If I had a dime every time I didn't know
what was going on, I'd be like, "Why is
everyone giving me all these dimes?"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About