3

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?

1 Answer 1

1
foreach($text_array as $line){
    foreach($regex_array as $regex{
        ...
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

That's the best way to do it? =)
Unfortunately I don't think this is a PHP Perl-style regular expression method that will do this. preg_replace and preg_filter both accept an array of expressions but they perform replacement in addition to matching.
What strikes you from this approach as too complex? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.