title: php overlapping Regex
body: <p>I'm trying to find all the results for Regex statement Which works to find the word to search for and ten words before and after.</p>
  <p>My problem is not Regex statement but overlapping in statements.</p>
  <p><em>I searched a lot but could not find a solution ,please help me</em></p>
  <pre><code>        /**
   * @param $q
   * @param $files
   * @return string
   */
  public function search($q, $files)
  {
      $regexp = '/(?:\w+\W+){0,10}\b' . $q . '\b(?:\W+\w+){0,10}/';
      $files = explode(&quot;,&quot;, $files);
      try{
      $files = File::find($files);
      $data = array();
      foreach ($files as $file) {
          $url = $file-&gt;file_path;
          preg_match_all($regexp, file_get_contents($url), $data[], PREG_PATTERN_ORDER);
      }
  
      $result = array();
      array_walk_recursive($data, function ($v, $k) use (&amp;$result) {
          $result[] = $v;
      });
      return response()-&gt;json($result,200);
      }catch (\Exception $e){
          return response()-&gt;json(&quot;error&quot;, 500);
      }
  }
  </code></pre>
  <hr />
  <p><strong>input :</strong></p>
  <p>Wikipedia is a free online encyclopedia, created and edited by volunteers around the world and hosted by the Wikimedia Foundation</p>
  <p>word for search : and</p>
  <p><strong>output i want:</strong></p>
  <ol>
  <li>Wikipedia is a free online encyclopedia, created and edited by volunteers around the world and hosted by the
  o</li>
  <li>online encyclopedia, created and edited by volunteers around the world and hosted by the Wikimedia Foundation</li>
  </ol>
  <hr />