Skip to content

Latest commit

 

History

History
520 lines (381 loc) · 11.3 KB

File metadata and controls

520 lines (381 loc) · 11.3 KB

Regex

  • class Regex (php\util\Regex)
  • package std
  • source php/util/Regex.php

Description

http://www.regular-expressions.info/java.html

Class Regex, Immutable


Static Methods

  • Regex ::of() - Creates a new Regex of regex with $string and $flag
  • Regex ::match() - Tells whether or not this string matches the given regular expression.
  • Regex ::split() - Splits this string around matches of the given regular expression.
  • Regex ::quote() - Returns a literal pattern String for the specified
  • Regex ::quoteReplacement() - Returns a literal replacement String for the specified

Methods

  • ->__construct() - Regex of $pattern and $flag
  • ->getPattern() - Get the current pattern.
  • ->getInput() - Get the input string.
  • ->getFlags() - Get the current flags
  • ->test() - Executes a search for a match between a regular expression and a specified string. Returns true or false.
  • ->matches() - Attempts to match the entire region against the pattern.
  • ->all() - Returns array of all found groups.
  • ->one() - Calls find() + groups() methods and returns the result of the groups() method.
  • ->first() - Alias of one() method.
  • ->last() - Finds the last match and returns last groups.
  • ->find() - Resets this matcher and then attempts to find the next subsequence of
  • ->replace() - Replaces every subsequence of the input sequence that matches the
  • ->replaceFirst() - Replaces the first subsequence of the input sequence that matches the
  • ->replaceGroup()
  • ->replaceWithCallback()
  • ->with() - Duplicates this pattern with a new $string
  • ->withFlags() - Clone this object with the new $flags
  • ->groups() - Returns an array of all group.
  • ->group() - Returns the input subsequence captured by the given group during the
  • ->groupNames() - Returns group names.
  • ->getGroupCount() - Returns the number of capturing groups in this matcher's pattern.
  • ->start() - Returns the start index of the previous match.
  • ->end() - Returns the offset after the last character matched.
  • ->hitEnd() - Returns true if the end of input was hit by the search engine in
  • ->requireEnd() - Returns true if more input could change a positive match into a
  • ->lookingAt() - Attempts to match the input sequence, starting at the beginning of the
  • ->region() - Sets the limits of this matcher's region. The region is the part of the
  • ->regionStart() - Reports the start index of this matcher's region. The
  • ->regionEnd() - Reports the end index (exclusive) of this matcher's region.
  • ->reset() - Resets this matcher.
  • ->current()
  • ->next()
  • ->key()
  • ->valid()
  • ->rewind()
  • ->__clone() - Class is immutable, the disallowed clone method

Static Methods

of()

Regex::of(string $pattern, int|string $flag, string $string): Regex

Creates a new Regex of regex with $string and $flag


match()

Regex::match(string $pattern, string $string, int|string $flags): bool

Tells whether or not this string matches the given regular expression. See also java.lang.String.matches()


split()

Regex::split(string $pattern, string $string, int $limit): array

Splits this string around matches of the given regular expression. See also java.lang.String.split()


quote()

Regex::quote(string $string): string

Returns a literal pattern String for the specified String.

This method produces a String that can be used to create a Regex that would match the string $string as if it were a literal pattern. Metacharacters or escape sequences in the input sequence will be given no special meaning.


quoteReplacement()

Regex::quoteReplacement(string $string): string

Returns a literal replacement String for the specified String.

This method produces a String that will work as a literal replacement $string in the replaceWithCallback() method of the php\util\Regex class. The String produced will match the sequence of characters in $string treated as a literal sequence. Slashes ('') and dollar signs ('$') will be given no special meaning.


Methods

__construct()

__construct(string $pattern, int|string $flag, string $string): void

Regex of $pattern and $flag


getPattern()

getPattern(): string

Get the current pattern.


getInput()

getInput(): string

Get the input string.


getFlags()

getFlags(): int

Get the current flags


test()

test(string $string): bool

Executes a search for a match between a regular expression and a specified string. Returns true or false.


matches()

matches(): bool

Attempts to match the entire region against the pattern.


all()

all(int $start): array

Returns array of all found groups.


one()

one(int $start): array|null

Calls find() + groups() methods and returns the result of the groups() method. Returns the first found groups, if founds nothing returns null.


first()

first(int $start): array

Alias of one() method.


last()

last(int $start): array

Finds the last match and returns last groups.


find()

find(int|null $start): bool

Resets this matcher and then attempts to find the next subsequence of the input sequence that matches the pattern, starting at the specified index.


replace()

replace(string $replacement): string

Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.

This method first resets this matcher. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string; each match is replaced in the result by the replacement string.


replaceFirst()

replaceFirst(string $replacement): string

Replaces the first subsequence of the input sequence that matches the pattern with the given replacement string.


replaceGroup()

replaceGroup(int $group, string $replacement): string

replaceWithCallback()

replaceWithCallback(callable $callback): string

with()

with(string $string): Regex

Duplicates this pattern with a new $string


withFlags()

withFlags(int|string $flags): Regex

Clone this object with the new $flags


groups()

groups(): array

Returns an array of all group.


group()

group(null|int $group): string

Returns the input subsequence captured by the given group during the previous match operation.


groupNames()

groupNames(): array

Returns group names.


getGroupCount()

getGroupCount(): int

Returns the number of capturing groups in this matcher's pattern.


start()

start(null|int $group): int

Returns the start index of the previous match.


end()

end(null|int $group): int

Returns the offset after the last character matched.


hitEnd()

hitEnd(): bool

Returns true if the end of input was hit by the search engine in the last match operation performed by this matcher.


requireEnd()

requireEnd(): bool

Returns true if more input could change a positive match into a negative one.

If this method returns true, and a match was found, then more input could cause the match to be lost. If this method returns false and a match was found, then more input might change the match but the match won't be lost. If a match was not found, then requireEnd has no meaning.


lookingAt()

lookingAt(): bool

Attempts to match the input sequence, starting at the beginning of the region, against the pattern.


region()

region(int $start, int $end): Regex

Sets the limits of this matcher's region. The region is the part of the input sequence that will be searched to find a match. Invoking this method resets the matcher, and then sets the region to start at the index specified by the $start parameter and end at the index specified by the $end parameter.


regionStart()

regionStart(): int

Reports the start index of this matcher's region. The searches this matcher conducts are limited to finding matches within regionStart() (inclusive) and regionEnd() (exclusive).


regionEnd()

regionEnd(): int

Reports the end index (exclusive) of this matcher's region. The searches this matcher conducts are limited to finding matches within regionStart() (inclusive) and regionEnd() (exclusive).


reset()

reset(null|string $string): $this

Resets this matcher.

Resetting a matcher discards all of its explicit state information and sets its append position to zero. The matcher's region is set to the default region, which is its entire character sequence. The anchoring and transparency of this matcher's region boundaries are unaffected.


current()

current(): null|string

next()

next(): void

key()

key(): int

valid()

valid(): bool

rewind()

rewind(): void

__clone()

__clone(): void

Class is immutable, the disallowed clone method