Get any field annotations with a matching tag.  Return these indexed by field name.

@param $string
8020
public function getFieldAnnotationsForMatchingTag($tag, $fieldName = null) {

        if ($fieldName) {
            return isset($this->fieldAnnotations[$fieldName][$tag]) ? $this->fieldAnnotations[$fieldName][$tag] : array();
        } else {

            $matchingAnnotations = array();
            foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {
                if (isset($fieldAnnotations[$tag])) {
                    $matchingAnnotations[$field] = $fieldAnnotations[$tag];
                }
            }

            return $matchingAnnotations;

        }
    }
93983
public static function parseAttributes($string)
	{
		// Initialise variables.
		$attr = array();
		$ret  = array();

		// Let's grab all the key/value pairs using a regular expression
		preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);

		if (is_array($attr))
		{
			$numPairs = count($attr[1]);
			for ($i = 0; $i < $numPairs; $i++)
			{
				$ret[$attr[1][$i]] = $attr[2][$i];
			}
		}

		return $ret;
	}
979595
protected function getEncodableWordTokens($string)
    {
        $tokens = [];

        $encodedToken = '';
        // Split at all whitespace boundaries
        foreach (preg_split('~(?=[\t ])~', $string) as $token) {
            if ($this->tokenNeedsEncoding($token)) {
                $encodedToken .= $token;
            } else {
                if (strlen($encodedToken) > 0) {
                    $tokens[] = $encodedToken;
                    $encodedToken = '';
                }
                $tokens[] = $token;
            }
        }
        if (strlen($encodedToken)) {
            $tokens[] = $encodedToken;
        }

        return $tokens;
    }
636267
public function strip_applet_tags_get_mathml($string) {
        if (stristr($string, '</APPLET>') === false) {
            return $string;
        } else {
            // Strip all applet tags keeping stuff before/after and inbetween (if mathml) them.
            while (stristr($string, '</APPLET>') !== false) {
                preg_match("/(.*)\<applet.*value=\"(\<math\>.*\<\/math\>)\".*\<\/applet\>(.*)/i", $string, $mathmls);
                $string = $mathmls[1].$mathmls[2].$mathmls[3];
            }
            return $string;
        }
    }
861814
private function filterEntities(string $string): string
    {
        return preg_replace_callback(
            '/&\w+;/',
            function ($match) {
                return str_repeat(' ', strlen($match[0]));
            },
            $string
        );
    }
347882
protected static function getStringTypeArray($type, $string, array &$matches)
    {
        return [
            Tokenizer::TOKEN_TYPE => $type,
            Tokenizer::TOKEN_VALUE => \substr($string, 0, \strlen($matches[1])),
        ];
    }
115117
protected function parseArguments($string)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');

        $args = array();
        $hash = array();
        
        $regex = array(
            '([a-zA-Z0-9]+\="[^"]*")',      // cat="meow"
            '([a-zA-Z0-9]+\=\'[^\']*\')',   // mouse='squeak squeak'
            '([a-zA-Z0-9]+\=[a-zA-Z0-9]+)', // dog=false
            '("[^"]*")',                    // "some\'thi ' ng"
            '(\'[^\']*\')',                 // 'some"thi " ng'
            '([^\s]+)'                      // <any group with no spaces>
        );
        
        preg_match_all('#'.implode('|', $regex).'#is', $string, $matches);
        
        $stringArgs = $matches[0];
        $name = array_shift($stringArgs);
        
        $hashRegex = array(
            '([a-zA-Z0-9]+\="[^"]*")',      // cat="meow"
            '([a-zA-Z0-9]+\=\'[^\']*\')',   // mouse='squeak squeak'
            '([a-zA-Z0-9]+\=[a-zA-Z0-9]+)', // dog=false
        );
        
        foreach ($stringArgs as $arg) {
            //if it's an attribute
            if (!(substr($arg, 0, 1) === "'" && substr($arg, -1) === "'")
                && !(substr($arg, 0, 1) === '"' && substr($arg, -1) === '"')
                && preg_match('#'.implode('|', $hashRegex).'#is', $arg)
            ) {
                list($hashKey, $hashValue) = explode('=', $arg, 2);
                $hash[$hashKey] = $this->parseArgument($hashValue);
                continue;
            }
            
            $args[] = $this->parseArgument($arg);
        }
        
        return array($name, $args, $hash);
    }
766999
private static function fromHStore($string)
    {
        $result = [];
        if (empty($string)) {
            return $result;
        }

        preg_match_all(
            '#"((?:\\\"|[^"])*)"=>"((?:\\\"|[^"])*)"#U',
            $string,
            $matches
        );
        foreach ($matches[1] as $id => $val) {
            $result[stripcslashes($val)] = stripcslashes($matches[2][$id]);
        }

        return $result;
    }
641562
private function parseGroupedNestedFields(StringObject $string)
    {
        $output = $this->str('');
        $currentPath = [
            'array'  => [],
            'string' => ''
        ];

        $parts = $string->explode('[');
        $lastPart = $parts->count() - 1;

        foreach ($parts as $index => $part) {

            $fields = explode(',', $part);

            $isLast = $index == $lastPart;

            if (!$isLast) {
                $newNestedKey = array_pop($fields) . '.';
            }

            foreach ($fields as $field) {

                $fullPath = '';

                if (substr($field, 0, 1) == '!') {
                    $fullPath = '!';
                    $field = ltrim($field, '!');
                }

                $closingBrackets = substr_count($field, ']');
                $field = rtrim($field, ']');

                $fullPath .= $currentPath['string'] . $field;

                $output->append($fullPath . ',');

                if ($closingBrackets > 0) {
                    $currentPath['array'] = array_slice($currentPath['array'], 0, count($currentPath['array']) - $closingBrackets);
                    $currentPath['string'] = implode('.', $currentPath['array']);
                }
            }

            if (!$isLast) {
                $currentPath['string'] .= $newNestedKey;
                $currentPath['array'][] = $newNestedKey;
            }
        }

        return $output->trimRight(',');
    }
595074
private function getAnyType($string)
    {
        $anyString = '';

        do {
            $anyString .= $string[0];
            $string = substr($string, 1);

            $typeInfo = $this->scanNextType($string);

            // ignore all until markup reached
            if ($typeInfo['type'] !== self::T_MARKUP_OPEN && $typeInfo['type'] !== self::T_MARKUP_OPEN_ESCAPED) {
                $typeInfo = null;
            }
        } while ($typeInfo === null && $string);

        return [
            'type'   => self::T_ANY,
            'match'  => $anyString,
            'length' => strlen($anyString),
        ];
    }
722866
public function getFieldAnnotationsNotContainingTags($tags = array()) {
        $matchingAnnotations = array();
        foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {

            $fieldAnnotationKeys = array_keys($fieldAnnotations);
            if (!array_intersect($fieldAnnotationKeys, $tags)) {
                $matchingAnnotations[$field] = $fieldAnnotations;
            }
        }

        return $matchingAnnotations;
    }
1241900
protected function convertToLookup($string) {
        $array = explode('|', str_replace(' ', '', $string));
        $ret = array();
        foreach ($array as $i => $k) {
            $ret[$k] = true;
        }
        return $ret;
    }
353896
private function _parseHADocField($string) {
    $separater = '=';
    $pos = strpos($string, $separater);

    if ($pos !== false) {
      $key = substr($string, 0, $pos);
      $value = substr($string, $pos + 1);
      return array($key, $value);
    } else {
      throw new Exception('The are no key and value in the field.');
    }
  }
365243
public function getArrayWhereKeysBeginWith($string)
    {
        if (empty($this->config)) {
            $this->getArray();
        }
        $config = $this->config;

        $thisConfig = array();
        $cleanNameLength = mb_strlen($string);
        $string = mb_strtolower($string);
        foreach ($config as $key => $value) {
            $begin = substr($key, 0, $cleanNameLength);
            if (mb_strtolower($begin) == $string) {
                $thisConfig[$key] = $value;
            }
        }
        return $thisConfig;
    }
658898
protected function getComparatorFromString($string)
    {
        foreach (self::$comparators as $comparator) {
            if (strpos($string, $comparator) !== false) {
                return $comparator;
            }
        }

        return null;
    }
290500
public function match($string)
    {

        $isMatch = preg_match($this->getRegularExpression(), $string, $matches);

        if (!$isMatch)
            return false;

        $vars = [];
        if (!empty($matches))
            foreach ($matches as $name => $value)
                if (is_string($name) && !empty($value))
                    $vars[$name] = $value;

        return $vars;
    }
631899
protected function _parseAttributes($string)
    {
        $result = array();

        if (!empty($string)) {
            $attr   = array();

            preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);

            if (is_array($attr)) {
                $numPairs = count($attr[1]);
                for ($i = 0; $i < $numPairs; $i++) {
                    $result[$attr[1][$i]] = $attr[2][$i];
                }
            }
        }

        return $result;
    }