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
Результат: string
getFlags
()¶Get the current flags
Результат: int
- static
of
($pattern, $flag = 0)¶Creates a new Regex of regex with $string and $flag
throws php\util\RegexException
Параметры:
- $pattern –
string
- regular expression- $flag –
int
- Regex::CASE_INSENSITIVE and other constantsРезультат:
matches
()¶Attempts to match the entire region against the pattern.
Результат: 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
Параметры:
- $start –
int
,null
Результат:
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
Параметры:
- $replacement –
string
Результат:
string
replaceFirst
($replacement)¶Replaces the first subsequence of the input sequence that matches the pattern with the given replacement string.
throws php\util\RegexException
Параметры:
- $replacement –
string
Результат:
string
replaceGroup
($group, $replacement)¶throws php\util\RegexException
Параметры:
- $group –
int
- $replacement –
string
Результат:
string
replaceWithCallback
($callback)¶throws php\util\RegexException
Параметры:
- $callback –
callable
- (Regex $pattern) -> stringРезультат:
string
with
($string)¶Duplicates this pattern with a new $string
Параметры:
- $string –
string
Результат:
withFlags
($flags)¶Clone this object with the new $flags
Параметры:
- $flags –
int
Результат:
group
($group = null)¶Returns the input subsequence captured by the given group during the previous match operation.
throws php\util\RegexException
Параметры:
- $group –
null
,int
Результат:
string
getGroupCount
()¶Returns the number of capturing groups in this matcher’s pattern.
Результат: int
start
($group = null)¶Returns the start index of the previous match.
throws php\util\RegexException
Параметры:
- $group –
null
,int
Результат:
int
end
($group = null)¶Returns the offset after the last character matched.
throws php\util\RegexException
Параметры:
- $group –
null
,int
Результат:
int
hitEnd
()¶Returns true if the end of input was hit by the search engine in the last match operation performed by this matcher.
Результат: 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.
Результат: bool
lookingAt
()¶Attempts to match the input sequence, starting at the beginning of the region, against the pattern.
Результат: 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
Параметры:
- $start –
int
- $end –
int
Результат:
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).
Результат: 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).
Результат: 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.
Параметры:
- $string –
null
,string
- The new input character sequenceРезультат:
php\util\$this
current
()¶
Результат: null
,string
next
()¶
key
()¶
Результат: int
valid
()¶
Результат: 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()
Параметры:
- $pattern –
string
- regular expression- $string –
string
- $flags –
int
Результат:
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
Параметры:
- $pattern –
string
- the delimiting regular expression- $string –
string
- $limit –
int
- the result thresholdРезультат:
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.
Параметры:
- $string –
string
- The string to be literalizedРезультат:
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.
Параметры:
- $string –
string
Результат:
string