Michael Grons
Michael Grons

Reputation: 705

PHP: Match line against array of regexes

I'm writing a quick PHP parser here and was wondering instead of writing

foreach($array as $line) {
  if(preg_match($regex1, ..) {

  } 
  elseif(preg_match($regex2, ..) {

  }
}

Is there possible to match against an array of regexes?

Upvotes: 3

Views: 222

Answers (1)

Álvaro González
Álvaro González

Reputation: 146563

foreach($text_array as $line){
    foreach($regex_array as $regex{
        ...
    }
}

Upvotes: 1

Related Questions