You are here

public static function FeedImportFilter::regex in Feed Import 8

Same name in this branch
  1. 8 feed_import_base/filters/feed_import_default_filters.php \FeedImportFilter::regex()
  2. 8 feed_import_base/src/Filter/FeedImportFilter.php \Drupal\feed_import_base\FeedImportFilter::regex()

Returns the matchd groups of regex

File

feed_import_base/src/Filter/FeedImportFilter.php, line 805

Class

FeedImportFilter
This class contains default filters for feed import.

Namespace

Drupal\feed_import_base

Code

public static function regex($field, $regex, $remove_indexes = FALSE) {
  if (is_array($field)) {
    foreach ($field as $key => &$f) {
      if (preg_match($regex, $f, $m)) {
        if ($remove_indexes) {
          $i = -1;
          while (isset($m[++$i])) {
            unset($m[$i]);
          }
        }
        else {
          array_shift($m);
        }
        $f = $m;
      }
      else {
        unset($field[$key]);
      }
    }
    return $field ? $field : NULL;
  }
  if (preg_match($regex, $field, $m)) {
    if ($remove_indexes) {
      $i = -1;
      while (isset($m[++$i])) {
        unset($m[$i]);
      }
    }
    else {
      array_shift($m);
    }
    return $m;
  }
  return NULL;
}