Regex¶
-
php\util\Regex
implements: Iterator
http://www.regular-expressions.info/java.html
Class Regex, Immutable
Constants
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:
- $pattern – string - regular expression
- $flag – int - Regex::CASE_INSENSITIVE and other constants
Returns:
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:
- $start – int, 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:
- $replacement – string
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:
- $replacement – string
Returns: string
replaceGroup
($group, $replacement)¶throws php\util\RegexException
Parameters:
- $group – int
- $replacement – string
Returns: string
replaceWithCallback
($callback)¶throws php\util\RegexException
Parameters:
- $callback – callable - (Regex $pattern) -> string
Returns: string
with
($string)¶Duplicates this pattern with a new $string
Parameters:
- $string – string
Returns:
withFlags
($flags)¶Clone this object with the new $flags
Parameters:
- $flags – int
Returns:
group
($group = null)¶Returns the input subsequence captured by the given group during the previous match operation.
throws php\util\RegexException
Parameters:
- $group – null, 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:
- $group – null, int
Returns: int
end
($group = null)¶Returns the offset after the last character matched.
throws php\util\RegexException
Parameters:
- $group – null, 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:
- $start – int
- $end – int
Returns:
regionStart
()¶Reports the start index of this matcher’s region. The searches this matcher conducts are limited to finding matches within
regionStart()
(inclusive) andregionEnd()
(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) andregionEnd()
(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:
- $string – null, 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:
- $pattern – string - regular expression
- $string – string
- $flags – int
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:
- $pattern – string - the delimiting regular expression
- $string – string
- $limit – int - 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 specifiedString
.This method produces a
String
that can be used to create aRegex
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:
- $string – string - The string to be literalized
Returns: string A literal string replacement
- static
quoteReplacement
($string)¶Returns a literal replacement
String
for the specifiedString
.This method produces a
String
that will work as a literal replacement $string in the replaceWithCallback() method of thephp\util\Regex
class. TheString
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:
- $string – string
Returns: string