Counting number of occurrences of a string inside another (Perl)

后端 未结 4 903
孤街浪徒
孤街浪徒 2020-12-01 09:25

What is the fastest way to count the number of times a certain string appears in a bigger one? My best guess would be to replace all instances of that string with nothing, c

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 09:33

    You could use a global regex. Something like:

    my @matches = $bigstring =~ /($littlestring)/g;
    my $count = @matches;
    

提交回复
热议问题