src/Parser.php
protected static function extractKeyword(
        string $haystack,
        string $needle,
        &$matches = null
    ) {
        $pattern = '/' . (strpos($needle, '^') === 0 ? '' : ' ?') . $needle
            . (strrpos($needle, '$') === strlen($needle)-1 ? '' : ' ?') . '/i';

        if (preg_match($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
            $m = $matches[0];
            $haystack = substr_replace($haystack, ' ', $m[1], strlen($m[0]));
            return trim($haystack);
        }
        return false;
    }
protected static function extractKeyword(
        string $haystack,
        string $needle,
        &$matches = null
    ) {
        $pattern = '/' . (strpos($needle, '^') === 0 ? '' : ' ?') . $needle
            . (strrpos($needle, '$') === strlen($needle)-1 ? '' : ' ?') . '/i';

        if (preg_match($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
            $m = $matches[0];
            $haystack = substr_replace($haystack, ' ', $m[1], strlen($m[0]));
            return trim($haystack);
        }
        return false;
    }
protected static function extractKeyword ( string $ haystack , string $ needle , & $ matches = null ) { $ pattern = '/' . ( strpos ( $ needle , '^' ) === 0 ? '' : ' ?' ) . $ needle . ( strrpos ( $ needle , '$' ) === strlen ( $ needle ) - 1 ? '' : ' ?' ) . '/i' ; if ( preg_match ( $ pattern , $ haystack , $ matches , PREG_OFFSET_CAPTURE ) ) { $ m = $ matches [ 0 ] ; $ haystack = substr_replace ( $ haystack , ' ' , $ m [ 1 ] , strlen ( $ m [ 0 ] ) ) ; return trim ( $ haystack ) ; } return false ; }
Extracts a keyword from a string

@param string $haystack String to look for the keyword
@param string $needle   PCRE subpattern with the keyword (insensitive)
@param string $matches  @see \preg_match() $matches (PREG_OFFSET_CAPTURE)

@return false  If the keyword was not found
@return string The string without the keyword
Extracts a keyword from a string