Raku By Example
View me onGitHub
## 将驼峰式标识符转为小写

for $=finish.lines -> $line {
     $line.say && next if $line.indices('_').elems >= 2;
     my @a = $line.trim.split('_');
     say @a[0].lc, '_', @a[1].comb(/<upper><lower>+/)>>.lc.join('_');
}

=finish
VCU_BrkPedSt
VCU_EMS_AccPedalActPst
DCU_RotSpdAct
DCU_TorqAct

## comb 与捕获

my $line = '{"pdfnum":"06342858","pdfnum":"06342854"';
.say for $line.comb(/pdfnum'":"'<( \w+ )>'"'/);

## \w+ 也能匹配中文
.comb(/TITLE \s* \" <( \w+ )>\"/)[0].say if /TITLE/ for $=finish.lines

=finish
PERFORMER "Various"
TITLE "宝丽金非常老牌精选"
FILE "CDImage.ape" WAVE
  TRACK 01 AUDIO
    TITLE "太阳一样"
    PERFORMER "刘文正"
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    TITLE "堆积情感"
    PERFORMER "邝美云"
    INDEX 00 03:28:07
    INDEX 01 03:30:10
  TRACK 03 AUDIO
    TITLE "时空寄情"
    PERFORMER "黄莺莺"
    INDEX 00 08:24:00
    INDEX 01 08:27:12
  TRACK 04 AUDIO
    TITLE "再见我的爱人"
    PERFORMER "邓丽君"
    INDEX 00 12:33:10
    INDEX 01 12:36:32
  TRACK 05 AUDIO
    TITLE "海角天涯"
    PERFORMER "王芷蕾"
    INDEX 00 16:03:02
    INDEX 01 16:06:07
  TRACK 06 AUDIO
    TITLE "廻"
    PERFORMER "李恕权"
    INDEX 00 19:30:30
    INDEX 01 19:33:22
  TRACK 07 AUDIO
    TITLE "故事的真相"
    PERFORMER "黄仲昆、杨林"
    INDEX 00 24:04:05
    INDEX 01 24:06:12
  TRACK 08 AUDIO
    TITLE "扬帆"
    PERFORMER "阳帆"
    INDEX 00 28:34:42
    INDEX 01 28:37:22

## 提取文本块
my $excerpt = q:to/END/;
Here's some unimportant text.
=begin code
This code block is what we're after.
We'll use 'ff' to get it.
=end code
More unimportant text.
=begin code
I want this line.
and this line as well.
HaHa
=end code
More unimport text.
=begin code
Let's to go home.
=end code
END

for $excerpt.comb(/^^ '=begin code' $$ \s* <( .+? )> \s+ ^^ '=end code' $$/) -> $c {
    say $c;
    say '-' x 15;
}