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

馋奶兔 提交于 2019-11-29 16:58:26
Marquis Wang

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.

See http://www.anaesthetist.com/mnm/perl/regex.htm . Basic syntax (from there) is:

$_ = "alpha xbetay xgammay xdeltay so on";
($first, $second, $third) = /x(.+?)y/g;

Note the /g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!