Regex

php\util\Regex

implements: Iterator

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

Class Regex, Immutable

Constants


constant CANON_EQ
constant CASE_INSENSITIVE
constant UNICODE_CASE
constant COMMENTS
constant DOTALL
constant LITERAL
constant MULTILINE
constant UNIX_LINES

Methods


__construct()

private

getPattern()

Get the current pattern

Returns:string
getFlags()

Get the current flags

Returns:int
static of($pattern, $flag = 0)

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

throws php\util\RegexException

Parameters:
  • $patternstring - regular expression
  • $flagint - Regex::CASE_INSENSITIVE and other constants
Returns:

php\util\Regex

matches()

Attempts to match the entire region against the pattern.

Returns:bool
find($start = null)

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

throws php\util\RegexException

Parameters:
  • $startint, null
Returns:

bool

replace($replacement)

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.

throws php\util\RegexException

Parameters:
  • $replacementstring
Returns:

string

replaceFirst($replacement)

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

throws php\util\RegexException

Parameters:
  • $replacementstring
Returns:

string

replaceGroup($group, $replacement)

throws php\util\RegexException

Parameters:
  • $groupint
  • $replacementstring
Returns:

string

replaceWithCallback($callback)

throws php\util\RegexException

Parameters:
  • $callbackcallable - (Regex $pattern) -> string
Returns:

string

with($string)

Duplicates this pattern with a new $string

Parameters:
  • $stringstring
Returns:

php\util\Regex

withFlags($flags)

Clone this object with the new $flags

Parameters:
  • $flagsint
Returns:

php\util\Regex

group($group = null)

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

throws php\util\RegexException

Parameters:
  • $groupnull, int
Returns:

string

getGroupCount()

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

Returns:int
start($group = null)

Returns the start index of the previous match.

throws php\util\RegexException

Parameters:
  • $groupnull, int
Returns:

int

end($group = null)

Returns the offset after the last character matched.

throws php\util\RegexException

Parameters:
  • $groupnull, int
Returns:

int

hitEnd()

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

Returns:bool
requireEnd()

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.

Returns:bool
lookingAt()

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

Returns:bool
region($start, $end)

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.

throws php\util\RegexException

Parameters:
  • $startint
  • $endint
Returns:

php\util\Regex

regionStart()

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).

Returns:int
regionEnd()

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).

Returns:int
reset($string = null)

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.

Parameters:
  • $stringnull, string - The new input character sequence
Returns:

php\util\$this

current()
Returns:null, string
next()
key()
Returns:int
valid()
Returns:bool
rewind()
__clone()

private

static match($pattern, $string, $flags = 0)

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

Parameters:
  • $patternstring - regular expression
  • $stringstring
  • $flagsint
Returns:

bool

static split($pattern, $string, $limit = 0)

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

throws php\util\RegexException

Parameters:
  • $patternstring - the delimiting regular expression
  • $stringstring
  • $limitint - the result threshold
Returns:

array the array of strings computed by splitting this string around matches of the given regular expression

static quote($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.

Parameters:
  • $stringstring - The string to be literalized
Returns:

string A literal string replacement

static quoteReplacement($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.

Parameters:
  • $stringstring
Returns:

string