1

I have an array containing regular expressions.
The point is that I want to run a function if any input string matches with any of these expressions whiteout any loops.

example of expressions array:

$array = [
       '^expression_(.*)',
       '^expression2_(.*)',
       'expression3',
];
1
  • Without any loops doesn't seem likely. Commented Sep 1, 2021 at 13:44

1 Answer 1

1

check this condition:

if(preg_match('/'.implode('|',$array).'/', $string)){

    //todo

}
Sign up to request clarification or add additional context in comments.

1 Comment

You may have to enclose them in brackets as well (). I am also unsure about the time complexity overhead that this might introduce over matching one by one.

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.