阅读(2197)
赞(6)
Laravel 8 matchAll {#collection-method}
2021-07-05 09:43:50 更新
matchAll
方法将会返回一个集合,该集合包含了指定字符串中与指定正则表达式匹配的部分:
use IlluminateSupportStr;
$result = Str::of('bar foo bar')->matchAll('/bar/');
// collect(['bar', 'bar'])
如果您在正则表达式中指定了一个匹配组, Laravel 将会返回与该组匹配的集合:
use IlluminateSupportStr;
$result = Str::of('bar fun bar fly')->matchAll('/f(w*)/');
// collect(['un', 'ly']);
如果没有找到任何匹配项,则返回空集合。