How can I do a global regular expression match in Perl?

前端 未结 2 1235
暗喜
暗喜 2020-12-22 01:41

I am trying to come up with a regular expression in Perl matching multiple patterns and returning all of them like preg_match_all in PHP does.

Here\'s w

2条回答
  •  北海茫月
    2020-12-22 02:18

    The Perl equivalent to

    preg_match_all('/(test|data|string)/', 'testdatastring', $m)
    

    is

    @m = ("testdatastring" =~ m/(test|data|string)/g);
    

    The /g flag stands for global, so it returns a list of matches in list context.

提交回复
热议问题