Search code examples
phpregexwildcardsymfony-2.7

Finder Class php - search keywords issue


I am working on symfony 2.7 and i am using finder class of php.

I am searching more then 1 keyword in the list of files.

I don't have any idea how to search more then 1 keyword using "contains" method of the finder class.

Below is my sample code.

$value = 'Leo Tiger';

$finder = new Finder();
$finder->in()->files()->contains($value);

My Concern is that i want to search "Leo" and "Tiger" both separately in diff files like elastic search will do.

How to use wildcard in finder method ?

I will really appreciate if anyone can help me this.


Solution

  • As you can see in comment to function contains the parameter $pattern can be (string or regexp). You can try use regex to find keywords Leo or Tiger:

    $finder = new Finder();
    $finder->in($dir)->files()->contains('/Leo|Tiger/');