Break and extract version from string.

@param $string

@throws GitTagNotFound

@return array
490106
public function extractVersion($string)
    {
        preg_match_all(
            $this->config->get('git.version.matcher'),
            $string,
            $matches
        );

        if (empty($matches[0])) {
            throw new GitTagNotFound('No git tags found in this repository');
        }

        return $matches;
    }
162895
public function parseString($string)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        foreach ($this->data as $key => $value) {
            $string = str_replace($key, $value, $string);
        }

        return $string;
    }
1238410
public static function stringToValueAndUnit(string $string): array
    {
        preg_match('/^([0-9.]+)([a-zA-Z]+)$/', $string, $matches);
        $value = (float) $matches[1];
        $unit = Mapper::getUnitFromAbbreviation($matches[2]);
        return [$value, $unit];
    }
1201625
public static function fromString($string)
    {
        if (preg_match(self::PATTERN_FROM_STRING, trim($string), $matches)) {
            if (2 === count($matches)) {
                // whole number
                return new self((int) $matches[1]);
            } else {
                // either x y/z or x/y
                if ($matches[2]) {
                    // x y/z
                    $whole = new self((int) $matches[1]);

                    return $whole->add(new self(
                        (int) $matches[2],
                        (int) $matches[3]
                    ));
                }

                // x/y
                return new self((int) $matches[1], (int) $matches[3]);
            }
        }

        throw new InvalidArgumentException(sprintf(
            'Cannot parse "%s"',
            $string
        ));
    }
981994
private static function split(string $string): array
    {
        $chars = [];

        for ($i = 0; $i < strlen($string); $i++) {
            $chars[] = $string[$i];
        }

        return $chars;
    }
383045
public static function filterPunctuation(string $string): string
    {
        $string = preg_replace('#[\x{2010}-\x{2015}\x{2053}]#u', '-', $string);
        $string = preg_replace('#[\x60\xB4\x{2B9}\x{2BB}-\x{2BF}\x{2018}-\x{201B}]#u', '\'', $string);
        $string = preg_replace('#[\xAB\xBB\x{2BA}\x{201C}-\x{201F}\x{2039}\x{203A}]#u', '"', $string);
        $string = preg_replace('#[\x{2116}]#u', '#', $string);

        return $string;
    }
416254
protected function doParse($string)
    {
        $userAgent = array(
            'string' => $this->cleanString($string),
            'browser_name' => null,
            'browser_version' => null,
            'browser_engine' => null,
            'operating_system' => null,
            'device' => 'Other'
        );

        if (empty($userAgent['string'])) {
            return $userAgent;
        }

        $browsers = $this->definition->getKnownBrowsers();
        $bots = $this->definition->getKnownBots();
        $userAgents = $browsers + $bots;

        // Find the right name/version phrase (or return empty array if none found)
        foreach ($userAgents as $name => $regexes) {
            if ($matches = $this->matchBrowser($regexes, $userAgent['string'])) {
                if (isset($matches[3])) {
                    $name = str_replace('*', strtolower($matches[2]), $name);
                }

                $userAgent['browser_name'] = $name;
                $userAgent['browser_version'] = end($matches);

                break;
            }
        }

        // Find browser engine
        $engines = $this->definition->getKnownEngines();
        if ($result = $this->find($engines, $userAgent['string'])) {
            $userAgent['browser_engine'] = $result;
        }

        // Find operating system
        $operatingSystems = $this->definition->getKnownOperatingSystems();
        if ($result = $this->find($operatingSystems, $userAgent['string'])) {
            $userAgent['operating_system'] = $result;
        }

        // Find device name
        $devices = $this->definition->getKnownDevices();
        if ($result = $this->find($devices, $userAgent['string'], true)) {
            $userAgent['device'] = $result;
        }

        return $userAgent;
    }
546365
public function cleanNewlines($string) {
        if ($max = $this->getConfig('maxNewlines')) {
            $string = preg_replace('/\n{' . ($max + 1) . ',}/', str_repeat("\n", $max), $string);
        }

        return trim($string);
    }
1195641
public static function cleanExtension(?string $string): ?string
    {
        // no extension in string is founded
        if (!self::contains('.', $string)) {
            return $string;
        }

        $splited = explode('.', $string);
        array_pop($splited);
        return implode('.', $splited);
    }
119341
protected function execute($string)
    {
        foreach ($this->patternsAndReplacements as $patternAndReplacement) {
            $tmp = preg_replace("/".$patternAndReplacement->pattern."/s", $patternAndReplacement->replacement, $string);
            if ($tmp === null) {
                InvalidExpression::invalidRegex($patternAndReplacement->pattern, $patternAndReplacement->replacement);
            } else {
                $string = $tmp;
            }
        }
        
        return $string;
    }
71028
private static function output($string)
    {
        if (self::is_cli()) {
            return $string . PHP_EOL;
        } else {
            $string = trim($string);
            if (!self::$use_pre) {
                return $string;
            }

            return $string;
        }
    }
95801
public function parse($string)
    {
        if (! $this->isSupports($string)) throw new \InvalidArgumentException('invalid string.');

        $define = new OptionDefine();
        preg_match($this->regexp_option, $string, $matches);

        // optional | required
        if ($matches[1] === 'require') $define->required();

        // long-name
        $define->setName($this->pickName($matches[2]));
        
        // short-name
        $define->setShortName($this->pickShortName($matches[2]));

        // defalt value
        $define->setDefault($this->pickValue($define, $matches[2]));
        
        // description
        $define->setDescription($this->pickDescription($matches));

        return $define;
    }
1206125
public static function parseRgbString(string $string) : array
    {
        if (!preg_match(self::REGEX_RGB, $string, $matches)) {
            throw InvalidArgumentException::format(
                    'Invalid rgb string passed to %s: expecting format "rgb(0-255, 0-255, 0-255)", "%s" given',
                    __METHOD__, $string
            );
        }

        return [(int)$matches[1], (int)$matches[2], (int)$matches[3]];
    }
188916
public static function fromString(string $versionString) : Version
    {
        if (!preg_match(
            '#^'
            . '(v|release\-)?'
            . '(?P<core>(?:[0-9]|[1-9][0-9]+)(?:\.(?:[0-9]|[1-9][0-9]+)){2})'
            . '(?:\-(?P<preRelease>[0-9A-Za-z\-\.]+))?'
            . '(?:\+(?P<build>[0-9A-Za-z\-\.]+))?'
            . '$#',
            $versionString,
            $parts
        )) {
            throw InvalidVersionStringException::forVersionString($versionString);
        }

        [$major, $minor, $patch] = explode('.', $parts['core']);
        $preRelease = !empty($parts['preRelease']) ? PreRelease::fromIdentifiersString($parts['preRelease']) : new NoPreRelease();
        $build = !empty($parts['build']) ? Build::fromIdentifiersString($parts['build']) : new NoBuild();

        return static::fromParts((int) $major, (int) $minor, (int) $patch, $preRelease, $build);
    }
1164982
protected function evaluateDateString($string)
    {
        $seconds = 1;
        $matches = [];
        preg_match('/^([0-9]*)([s|M|h|d|m|y])$/', $string, $matches);

        switch ($matches[2]) {
            case 's':
                $seconds = $matches[1];
                break;
            case 'M':
                $seconds = $this->evaluateDateString(60 * $matches[1] . 's');
                break;
            case 'h':
                $seconds = $this->evaluateDateString(60 * $matches[1] . 'M');
                break;
            case 'd':
                $seconds = $this->evaluateDateString(24 * $matches[1] . 'h');
                break;
            case 'm':
                $seconds = $this->evaluateDateString(30 * $matches[1] . 'd');
                break;
            case 'y':
                $seconds = $this->evaluateDateString(12 * $matches[1] . 'm');
                break;
        }

        return $seconds;
    }
367044
public static function removePunctuation($string)
    {
        $string = self::removeTrailingPunctuation($string);
        $string = self::removeLeadingPunctuation($string);
        return $string;
    }
100254
private function separateSelectString(string $string)
    {
        if (false === strpos($string, '(')) {
            return array_map('trim', explode(',', $string));
        }

        $opened = $closed = 0;
        $cnt = mb_strlen($string);
        $arrayStrings = [];
        $substring = '';

        for ($i = 0; $i < $cnt; $i++) {
            $substring .= $string[$i];
            if ('(' === $string[$i]) {
                $opened++;
            } elseif (')' === $string[$i]) {
                $closed++;
            } elseif (',' === $string[$i] && $opened === $closed) {
                $arrayStrings[] = trim($substring);
            }
        }
        $arrayStrings[] = trim($substring);

        return $arrayStrings;
    }