match

@param string      $pattern
@param string      $string
@param string|null $option
@param string|null $encoding

@return  bool
1559
public static function match($pattern, $string, $option = 'msr', $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        $encodingBackup = mb_regex_encoding();

        mb_regex_encoding($encoding);

        $result = mb_ereg_match($pattern, $string, $option);

        mb_regex_encoding($encodingBackup);

        return $result;
    }
887363
private function match($template, $pattern)
    {
        if (empty($pattern)) {
            return null;
        }

        return false !== strpos($template, $pattern);
    }
294093
public function matches($pattern): bool
    {
        Assert::typeOf(['string', __CLASS__], $pattern);

        return preg_match((string) $pattern, $this->data) === 1;
    }
787884
public static boolean contains(Pattern pattern, CharSequence content) {
		if (null == pattern || null == content) {
			return false;
		}
		return pattern.matcher(content).find();
	}
554485
public static function Match ($pattern, $subject, array &$matches = array(), $flags = 0, $offset = 0, $from_encoding = Encoding::DEFAULT_ENCODING) {
		return Regex::match($pattern, $subject, $matches, $flags, $offset, $from_encoding);
	}
128496
def _match(string, pattern):
    
    p = pattern
    try:
        if p[:1] == WILDCARD and (p[-1:] == WILDCARD and p[1:-1] in string or string.endswith(p[1:])):
            return True
        if p[-1:] == WILDCARD and not p[-2:-1] == "\\" and string.startswith(p[:-1]):
            return True
        if p == string:
            return True
        if WILDCARD in p[1:-1]:
            p = p.split(WILDCARD)
            return string.startswith(p[0]) and string.endswith(p[-1])
    except:
        # For performance, calling isinstance() last is 10% faster for plain strings.
        if isinstance(p, regexp):
            return p.search(string) is not None
    return False
1371768
protected function eregReplace($pattern, $replacement, $string, $option = 'msr')
	{
		trigger_error('Function ' . __METHOD__ . ' not implemented yet');

		static $functionExists;
		if ($functionExists === null) {
			$functionExists = function_exists('\mb_split');
		}

		if ($functionExists) {
			return \mb_ereg_replace($pattern, $replacement, $string, $option);
		} else if ($this->supportsEncoding()) {
			$option = str_replace('r', '', $option);
			return \preg_replace("/$pattern/u$option", $replacement, $string);
		}
	}
1270556
protected function match(array &$str, $pattern, $keep)
    {
        $tokens = array();
        foreach ($str as $s) {
            preg_match_all($pattern, $s, $m);
            $tokens = array_merge(
                $tokens,
                $m[$keep]
            );
        }

        $str = $tokens;
    }
663325
public static function toggleCase($string, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        return preg_replace_callback(
            '/[\S]/u',
            function ($match) use ($encoding) {
                if ($match[0] === Mbstring::strtoupper($match[0], $encoding)) {
                    return Mbstring::strtolower($match[0], $encoding);
                }

                return Mbstring::strtoupper($match[0], $encoding);
            },
            $string
        );
    }
117894
public function acfLocationRulesMatch($match, $rule, $options)
    {
        $post_types = get_field('easy_reading_posttypes', 'option');

        if ($post_types) {
            if ($rule['operator'] == "==") {
                $match = (isset($options['post_type']) && in_array($options['post_type'], $post_types) && $options['post_id'] > 0);
            } elseif ($rule['operator'] == "!=") {
                $match = (isset($options['post_type']) && !in_array($options['post_type'], $post_types) && $options['post_id'] > 0);
            }
        }

        return $match;
    }
1055744
public function match($pattern) {
        if (!$this->_isValid) {
            return $this;
        }
        if (!preg_match($pattern, $this->_unsafeVar)) {
            $this->_isValid = false;
        }
        return $this;
    }
1173502
public function match(string $pattern, Event $event) : bool
    {
        return $this->matchEventName($pattern, $event);
    }
1047046
public static String match(String pattern, String reg) {

        String match = null;
        List<String> matches = match(pattern, reg, 0);
        if (null != matches && matches.size() > 0) {
            match = matches.get(0);
        }
        return match;
    }
789567
public static function ensureLeft($string, $search, $encoding = null)
    {
        if (static::startsWith($string, $search, true, $encoding)) {
            return $string;
        }

        return $search . $string;
    }
455920
private function find($pattern, $offset = null, $normal = false)
    {
        $source = $this->source;
        $offset = ($offset === null) ? $source->cursor : $offset;
        if ($offset >= $source->bound) {
            $this->addError('The scope of the parsing template is beyond the length of the template content');
            return null;
        }
        $content = $source->substring($offset, $source->bound);
        if (!preg_match($pattern, $content, $match, PREG_OFFSET_CAPTURE)) {
            return null;
        }
        $ret = $match[0];
        $length = strlen($ret[0]);
        if ($length == 0) {
            return null;
        }
        $start = $offset + $ret[1];
        $end = $start + $length;
        if ($normal) {
            return ['val' => $ret[0], 'idx' => 0, 'start' => $start, 'end' => $end, 'len' => $length];
        }
        $match = array_filter($match, function ($item) {
            return $item[1] != -1;
        });
        foreach ($match as $k => &$v) {
            $v[2] = $k - 1;
        }
        $ret = end($match);
        return ['val' => $ret[0], 'idx' => $ret[2], 'start' => $start, 'end' => $end, 'len' => $length];
    }
861978
public static Options parsePattern(String pattern)
    {
        char opt = ' ';
        boolean required = false;
        Class<?> type = null;

        Options options = new Options();

        for (int i = 0; i < pattern.length(); i++)
        {
            char ch = pattern.charAt(i);

            // a value code comes after an option and specifies
            // details about it
            if (!isValueCode(ch))
            {
                if (opt != ' ')
                {
                    final Option option = Option.builder(String.valueOf(opt))
                        .hasArg(type != null)
                        .required(required)
                        .type(type)
                        .build();
                    
                    // we have a previous one to deal with
                    options.addOption(option);
                    required = false;
                    type = null;
                    opt = ' ';
                }

                opt = ch;
            }
            else if (ch == '!')
            {
                required = true;
            }
            else
            {
                type = (Class<?>) getValueClass(ch);
            }
        }

        if (opt != ' ')
        {
            final Option option = Option.builder(String.valueOf(opt))
                .hasArg(type != null)
                .required(required)
                .type(type)
                .build();
            
            // we have a final one to deal with
            options.addOption(option);
        }

        return options;
    }
785552
function matches( $pattern, $content, $id ) {
		$matches = null;
		if ( preg_match_all( $pattern, $content, $matches, PREG_OFFSET_CAPTURE ) > 0 ) {
			// Reduce memory usage by doing preg_replace() for the same $pattern/$replacement combination only once
			$content_replace = preg_replace( $pattern, $this->replace, $content );
			$results = [];
			foreach ( $matches[0] as $found ) {
				if ( empty( $found[0] ) ) {
					continue; // Some weird regex looking for nothing?
				}
				$result = new Result();
				$result->id = $id;
				$result->offset = $found[1];
				$result->length = strlen( $found[0] );
				// Extract the context - surrounding 40 characters either side
				// Index 0 is the match, index 1 is the position

				$start = $found[1] - 40;
				if ( $start < 0 ) {
					$start = 0;
				}

				$end = $found[1] + 40;
				if ( $end > strlen( $content ) ) {
					$end = strlen( $content );
				}

				$end -= $start;
				$left = ltrim( substr( $content, $start, $found[1] - $start ), " \t," );
				$right = rtrim( substr( $content, $found[1] + strlen( $found[0] ), $end ), " \t," );
				$result->left = $start;
				$result->left_length = strlen( $found[0] ) + ( $found[1] - $start ) + $end;
				if ( 0 !== $start ) {
					$result->search = '&hellip;';
				}
				$result->search .= esc_html( $left );
				$result->search .= '<del>' . esc_html( $found[0] ) . '</del>';
				$result->search .= esc_html( $right );
				$result->search_plain = esc_html( $left );
				$result->search_plain .= esc_html( $found[0] );
				$result->search_plain .= esc_html( $right );
				if ( $start + $end < strlen( $content ) ) {
					$result->search .= '&hellip;';
				}
				if ( ! is_null( $this->replace ) ) {
					// Produce preview
					$rep = preg_replace( $pattern, $this->replace, $found[0] );
					$result->replace_string = $rep;
					if ( 0 !== $start ) {
						$result->replace = '&hellip;';
					}
					$result->replace .= esc_html( $left );
					$result->replace .= '<ins>' . esc_html( $rep ) . '</ins></a>';
					$result->replace .= esc_html( $right );
					$result->left_length_replace = strlen( $left ) + strlen( $rep ) + strlen( $right ) + 1;
					$result->replace_plain  = esc_html( $left );
					$result->replace_plain .= esc_html( $rep );
					$result->replace_plain .= esc_html( $right );
					if ( $start + $end < strlen( $content ) ) {
						$result->replace .= '&hellip;';
					}
					// And the real thing
					$result->content = $content_replace;
				}
				$results[] = $result;
			}
			return $results;
		}
		return false;
	}