Skip to main content

Release 0.9.8 - foreach baby, foreach!


Up to this point, you could either use T-Regx methods that return array, in order to iterate them, or use one of the collection methods map(), forEach(), filter(), etc.

Right now any chainable method in T-Regx is also iterate

foreach (pattern('\d+')->match('') as $match) {
foreach (pattern('\d+')->match('')->asInt() as $digit) {
foreach (pattern('\d+')->match('')->all() as $text) {

Shorthand method#

In addition to previous release, when we added asArray() method, we also added a shorthand get() method for capturing groups.

pattern('(origin/)?master')->match('master')->first(function (Match $match) {
$match->get(1); // same as $match->group(1)->text();