On 01/16/2018 12:57 AM, Elizabeth Mattijsen wrote:

On 16 Jan 2018, at 09:46, ToddAndMargo <toddandma...@zoho.com> wrote:
I want to match the next two character (don't care what
they are) in the following

I will use ?? for the next two character, but that doesn't work
$x ~~ m/.*?(sd??).*/;

I want $0 to include the "sd" and the next two characters, whatever
they are.

$x ~~ m/ (sd..) /;

. stands for any character


Liz


Interesting.  I do not have to use the `/*?` and `.*`.

$ perl6 -e 'my $x="abcsdd1efg"; $x ~~ m/ (sd..) /; say "$0"'
sdd1

$ perl6 -e 'my $x="abcsdd1efg"; $x ~~ m/.*?(sd..).*/; say "$0"'
sdd1

perl6 -e 'my $x="abcsdd1efg"; $x ~~ m/ (sd..)/; say "$0"'
sdd1

$ perl6 -e 'my $x="abcsdd1efg"; $x ~~ m/(sd..)/; say "$0"'
sdd1


But I do have to use `.*?` in the middle when matching two things

$ perl6 -e 'my $x="abcsdd1efg1234xyz"; $x ~~ m/(sd..) (12..)/; say "$0, $1"'
Use of Nil in string context
  in block <unit> at -e line 1
Use of Nil in string context
  in block <unit> at -e line 1


$ perl6 -e 'my $x="abcsdd1efg1234xyz"; $x ~~ m/(sd..).*?(12..)/; say "$0, $1"'
sdd1, 1234

Thank you Liz!

-T

Reply via email to