On Sat, Sep 23, 2017 at 3:54 PM, ToddAndMargo <[email protected] <mailto:[email protected]>> wrote:>> Hi All, >> >> Question. Can I chain these two substitutions together? >> >> $ perl6 -e 'my $x=" State : abc "; $x ~~ s/.*?" : "//; $x ~~ s/" >> ".*//; say "<$x>";' >> >> <abc> >> >> Many thanks, >> -TOn 09/23/2017 07:58 AM, raiph mellor wrote: You want to do two things: 1. match/replace something 2. match/replace something else To do this in one command you need: * `:g` to tell P6 to keep going after the first match * `||` to tell P6 to match what's on the left first, or if that fails, what's on the right Which yields: my $x=" State : abc "; $x ~~ s:g/.*?" : "||" ".*//; say "<$x>"; # <abc> On Sat, Sep 23, 2017 at 1:29 AM, ToddAndMargo <[email protected] <mailto:[email protected]>> wrote: Thank you!
On 09/24/2017 01:09 PM, yary wrote: > Here's another solution: > > my $x="State : abc "; $x = $x.subst(/.*?" : "/, "").subst(/ " "+ /,""); > say "<$x>"; # <abc> > > > -y > Now that is a thing of beauty! Thank you!
