Thursday 29 March 2018

Match (a AND b) vs (a OR b) in PHP regex

I'm trying to search through some files in PHP and I want to give the user a choice between matching any or every term.



E.g.: Search terms: [apple,banana]



Is it possible to return only files that have both words in it?




Also my OR would use the following:



$s_terms = "(" . implode("|", explode(",", $s_terms)) . ")";



I want to separate terms with , and use it in a RegEx match like (apple|banana). Does the above code do that?



Thank you in forward



EDIT:




The other question did not answer my question, but I found something that works:
(.*apple.*banana.*)

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...