@param string $pattern
@param string $word

@return int position from left where the pattern matched from right otherwise -1
974708
protected function match($pattern, $word)
    {
        if (substr($pattern, 0, 1) !== '-') // compare if the first byte is ascii `-`
        {
            return strcasecmp($pattern, $word) === 0 ? 0 : -1;
        }

        $matches = [];
        if (preg_match('/' . substr($pattern, 1) . '$/iu', $word, $matches)) {
            for ($i = count($matches) - 1; $i > 0; $i--) {
                $this->replacements[$i - 1] = $matches[count($matches) - $i];
            }

            return mb_strlen($word, 'UTF-8') - mb_strlen($matches[0], 'UTF-8');
        }

        return -1;
    }
75932
public static function rtrimWord($string, $word)
    {
        $end = mb_substr($string, 0-mb_strlen($word));
        if ($end != $word) {
            return $string;
        }
        return mb_substr($string, 0, mb_strlen($string)-mb_strlen($word));
    }
1200910
def getPattern(self, word):
        
        if word in self.patterns:
            return self.patterns[word]
        else:
            raise ValueError('Unknown pattern in getPattern().', word)
137385
public function disambiguate($word)
    {
        $matches  = null;
        $contains = preg_match('/^men([aiueo])(.*)$/', $word, $matches);

        if ($contains === 1) {
            return 'n' . $matches[1] . $matches[2];
        }
    }
62103
protected function parsePattern($pattern)
    {
        $patterns = explode(';', $pattern);
        if (!isset($patterns[1])) {
            // No explicit negative pattern was provided, construct it.
            $patterns[1] = '-' . $patterns[0];
        }
        return $patterns;
    }
820664
private function matchesPattern($pattern) {
        $regexEncoding = mb_regex_encoding();
        mb_regex_encoding($this->encoding);

        $match = mb_ereg_match($pattern, $this->str);
        mb_regex_encoding($regexEncoding);

        return $match;
    }
395221
public static int countsForBigram(String text, String pattern) {
        int count = 0;
        int index = -1;
        while (true) {
            index = text.indexOf(pattern, index + 1);
            if (index > -1) {
                LOG.debug("模式: " + pattern + " 出现在文本中的位置：" + index);
                count++;
            } else {
                break;
            }
        }
        return count;
    }
1370744
protected function getValueOfDocLine( $line, $pattern )
	{
		$parts	= explode( $this->patterns[$pattern], $line );
		$value	= trim( $parts[1] );
		return $value;
	}
1053356
public static function find($pattern, $entries)
    {
        if (is_array($pattern))
        {
            return static::findFew($pattern, $entries);
        }

        return static::findOne($pattern, $entries);
    }
85779
static public function select(string $pattern = '*', int $count = 1000): \Iterator
    {
        $iterator = null;
        while (true) {
            $ret = self::handle()->scan($iterator, $pattern, $count);
            if (false == $ret) {
                break;
            }
            foreach ($ret as $item) {
                yield $item;
            }
        }
    }
1159647
public function getMatchAll(string $pattern, int $flags = PREG_PATTERN_ORDER, int $offset = 0)
	{
		return preg_match_all($pattern, $this->str, $matches, $flags, $offset) === false ? null : $matches;
	}
274718
private int getMatchingPoint(String pattern, String itemName) {
        int index = pattern.indexOf('*');
        if (index == -1) {
            return -1;
        }

        String firstPart = pattern.substring(0, index);
        int indexFirstPart = itemName.indexOf(firstPart, 0);
        if (indexFirstPart == -1) {
            return -1;
        }

        String secondPart = pattern.substring(index + 1);
        int indexSecondPart = itemName.indexOf(secondPart, index + 1);
        if (indexSecondPart == -1) {
            return -1;
        }

        return firstPart.length() + secondPart.length();
    }
333389
private function parseSizeWord($word)
    {
        $sizeWord = strtoupper(preg_replace('/([a-z])([A-Z])/', '$1_$2', $word));
        if (array_key_exists($sizeWord, $this->sizes)) {
            $size = $this->sizes[$sizeWord];
        } else {
            $size = 0;
        }
        return $size;
    }
1255882
protected function parsePattern($pattern)
    {
        $currentPos      = 0;
        $length          = strlen($pattern);
        $tokens          = [];
        $level           = 0;
        $quotedDelimiter = preg_quote($this->delimiter);

        while ($currentPos < $length) {
            preg_match('(\G(?P<literal>[^:{\[\]]*)(?P<token>[:\[\]]|$))', $pattern, $matches, 0, $currentPos);

            $currentPos += strlen($matches[0]);

            if (!empty($matches['literal'])) {
                $tokens[] = ['literal', $matches['literal']];
            }

            if ($matches['token'] === ':') {
                if (!preg_match(
                    '(\G(?P<name>[^:' . $quotedDelimiter . '{\[\]]+)(?:{(?P<delimiters>[^}]+)})?:?)',
                    $pattern,
                    $matches,
                    0,
                    $currentPos
                )) {
                    throw new Exception\RuntimeException('Found empty parameter name');
                }

                $tokens[] = [
                    'parameter',
                    $matches['name'],
                    isset($matches['delimiters']) ? $matches['delimiters'] : null
                ];

                $currentPos += strlen($matches[0]);
            } elseif ($matches['token'] === '[') {
                $tokens[] = ['optional-start'];
                $level++;
            } elseif ($matches['token'] === ']') {
                $tokens[] = ['optional-end'];
                $level--;

                if ($level < 0) {
                    throw new Exception\RuntimeException('Found closing bracket without matching opening bracket');
                }
            } else {
                break;
            }
        }

        if ($level > 0) {
            throw new Exception\RuntimeException('Found unbalanced brackets');
        }

        return $tokens;
    }
59736
private function findIn(array $collection, $index, $pattern)
    {
        $total = count($collection);
        while ($index < $total) {
            $found = $this->match($pattern, $collection, $index++);
            if ($found !== false) {
                $token = $collection[$found];

                return $token->getLineNumber();
            }
        }

        return false;
    }
82001
public function matchPattern(string $pattern) : Element
    {
        $this->attributes['pattern'] = $pattern;
        return $this->addTest('pattern', function ($value) use ($pattern) {
            return preg_match("@^$pattern$@", trim($value));
        });
    }
506263
public static int getReorderCode(String word) {
        for(int i = 0; i < gSpecialReorderCodes.length; ++i) {
            if(word.equalsIgnoreCase(gSpecialReorderCodes[i])) {
                return Collator.ReorderCodes.FIRST + i;
            }
        }
        try {
            int script = UCharacter.getPropertyValueEnum(UProperty.SCRIPT, word);
            if(script >= 0) {
                return script;
            }
        } catch (IllegalIcuArgumentException e) {
            // fall through
        }
        if(word.equalsIgnoreCase("others")) {
            return Collator.ReorderCodes.OTHERS;  // same as Zzzz = USCRIPT_UNKNOWN 
        }
        return -1;
    }