ClassGo
Regexp\CompilePOSIX
class Regexp\CompilePOSIX {
- public function __construct(string $expr);
- public function append_text(string $b): string;
- public function copy(): Regexp\Compile;
- public function expand(string $dst, string $template, string $src, array $match): string;
- public function expand_string(string $dst, string $template, string $src, array $match): string;
- public function find(string $b): string;
- public function find_all(string $b, int $n): array;
- public function find_all_index(string $b, int $n): array;
- public function find_all_string(string $s, int $n): array;
- public function find_all_string_index(string $s, int $n): array;
- public function find_all_string_submatch(string $s, int $n): array;
- public function find_all_string_submatch_index(string $s, int $n): array;
- public function find_all_submatch(string $b, int $n): array;
- public function find_all_submatch_index(string $b, int $n): array;
- public function find_index(string $b): array;
- public function find_reader_index(object $r): array;
- public function find_reader_submatch_index(object $r): array;
- public function find_string(string $s): string;
- public function find_string_index(string $s): array;
- public function find_string_submatch(string $s): array;
- public function find_string_submatch_index(string $s): array;
- public function find_submatch(string $b): array;
- public function find_submatch_index(string $b): array;
- public function literal_prefix(): array;
- public function longest(): void;
- public function marshal_text(): string;
- public function match(string $b): bool;
- public function match_reader(object $r): bool;
- public function match_string(string $s): bool;
- public function num_subexp(): int;
- public function replace_all(string $src, string $repl): string;
- public function replace_all_func(string $src, callable $repl): string;
- public function replace_all_literal(string $src, string $repl): string;
- public function replace_all_literal_string(string $src, string $repl): string;
- public function replace_all_string(string $src, string $repl): string;
- public function replace_all_string_func(string $src, callable $repl): string;
- public function split(string $s, int $n): array;
- public function subexp_index(string $name): int;
- public function subexp_names(): array;
- public function unmarshal_text(string $text): void;
}
Description
Regexp\CompilePOSIX compiles $expr as POSIX ERE, where a match is the leftmost-longest one and not the leftmost one Perl syntax finds.
Regexp\CompilePOSIX is a class phpscript declares.
$object = new Regexp\CompilePOSIX($expr);
Methods
public function append_text(string $b): string-
append_text implements [encoding.TextAppender]. The output matches that of calling the [Regexp.String] method.
Note that the output is lossy in some cases: This method does not indicate POSIX regular expressions (i.e. those compiled by calling [CompilePOSIX]), or those for which the [Regexp.Longest] method has been called.
The go method
AppendText. public function copy(): Regexp\Compile-
copy returns a new [Regexp] object copied from re. Calling [Regexp.Longest] on one copy does not affect another.
Deprecated: In earlier releases, when using a [Regexp] in multiple goroutines, giving each goroutine its own copy helped to avoid lock contention. As of Go 1.12, using Copy is no longer necessary to avoid lock contention. Copy may still be appropriate if the reason for its use is to make two copies with different [Regexp.Longest] settings.
The go method
Copy. public function expand(string $dst, string $template, string $src, array $match): string-
expand appends template to dst and returns the result; during the append, Expand replaces variables in the template with corresponding matches drawn from src. The match slice should have been returned by [Regexp.FindSubmatchIndex].
In the template, a variable is denoted by a substring of the form $name or ${name}, where name is a non-empty sequence of letters, digits, and underscores. A purely numeric name like $1 refers to the submatch with the corresponding index; other names refer to capturing parentheses named with the (?P<name>...) syntax. A reference to an out of range or unmatched index or a name that is not present in the regular expression is replaced with an empty slice.
In the $name form, name is taken to be as long as possible: $1x is equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0.
To insert a literal $ in the output, use $$ in the template.
The go method
Expand. public function expand_string(string $dst, string $template, string $src, array $match): string-
expand_string is like [Regexp.Expand] but the template and source are strings. It appends to and returns a byte slice in order to give the calling code control over allocation.
The go method
ExpandString. public function find(string $b): string-
find returns the text of the leftmost match for re in b. The return value is nil for no match.
The go method
Find. public function find_all(string $b, int $n): array-
find_all returns all the matches for re in b. If n >= 0, FindAll returns no more than n matches. See [Regexp.All] for the equivalent iterator form.
The go method
FindAll. public function find_all_index(string $b, int $n): array-
find_all_index returns the locations of all matches for re in b. If n >= 0, FindAllIndex returns no more than n matches. See [Regexp.AllIndex] for the equivalent iterator form.
The go method
FindAllIndex. public function find_all_string(string $s, int $n): array-
find_all_string returns all the matches for re in s. If n >= 0, FindAllString returns no more than n matches. See [Regexp.AllString] for the equivalent iterator form.
The go method
FindAllString. public function find_all_string_index(string $s, int $n): array-
find_all_string_index returns the locations of all matches for re in s. If n >= 0, FindAllStringIndex returns no more than n matches. See [Regexp.AllStringIndex] for the equivalent iterator form.
The go method
FindAllStringIndex. public function find_all_string_submatch(string $s, int $n): array-
find_all_string_submatch returns the locations of all matches for re in s, including submatch locations. In each returned match m, m[0] is the overall match, m[1] is the first submatch, and so on. If n >= 0, FindAllStringSubmatch returns no more than n matches. See [Regexp.AllStringSubmatch] for the equivalent iterator form.
The go method
FindAllStringSubmatch. public function find_all_string_submatch_index(string $s, int $n): array-
find_all_string_submatch_index returns the locations of all matches for re in s, including submatch locations. In each returned match m, the overall match is s[m[0]:m[1]], the first submatch is s[m[2]:m[3]], and so on. If n >= 0, FindAllStringSubmatchIndex returns no more than n matches. See [Regexp.AllStringSubmatchIndex] for the equivalent iterator form.
The go method
FindAllStringSubmatchIndex. public function find_all_submatch(string $b, int $n): array-
find_all_submatch returns the locations of all matches for re in b, including submatch locations. In each returned match m, the overall match is m[0], the first submatch is m[1], and so on. If n >= 0, FindAllSubmatch returns no more than n matches. See [Regexp.AllSubmatch] for the equivalent iterator form.
The go method
FindAllSubmatch. public function find_all_submatch_index(string $b, int $n): array-
find_all_submatch_index returns the locations of all matches for re in b, including submatch locations. In each returned match m, the overall match is b[m[0]:m[1]], the first submatch is b[m[2]:m[3]], and so on. If n >= 0, FindAllSubmatchIndex returns no more than n matches. See [Regexp.AllSubmatchIndex] for the equivalent iterator form.
The go method
FindAllSubmatchIndex. public function find_index(string $b): array-
find_index returns the location of the leftmost match for re in b. The match itself is at b[m[0]:m[1]]. The return value is nil for no match.
The go method
FindIndex. public function find_reader_index(object $r): array-
find_reader_index returns the location of the leftmost match for re in r. The match starts at byte index m[0] and ends just before byte index m[1]. The return value is nil for no match.
FindReaderIndex may read arbitrarily far from r, including reading beyond the returned match.
The go method
FindReaderIndex. public function find_reader_submatch_index(object $r): array-
find_reader_submatch_index returns the first match for re in r, including submatches. The overall match is at byte index m[0] up to m[1], the first submatch is at byte index m[2] up to m[3], and so on. The return value is nil for no match.
FindReaderSubmatchIndex may read arbitrarily far from r, including reading beyond the returned match.
The go method
FindReaderSubmatchIndex. public function find_string(string $s): string-
find_string returns the text of the leftmost match for re in s. The return value is the empty string both for an empty match and for no match. To distinguish those two cases, use [Regexp.FindStringIndex] or [Regexp.FindStringSubmatch].
The go method
FindString. public function find_string_index(string $s): array-
find_string_index returns the location of the leftmost match for re in s. The match itself is at s[m[0]:m[1]]. The return value is nil for no match.
The go method
FindStringIndex. public function find_string_submatch(string $s): array-
find_string_submatch returns the first match for re in s, including submatches. The overall match is s[0], the first submatch is s[1], and so on. The return value is nil for no match.
The go method
FindStringSubmatch. public function find_string_submatch_index(string $s): array-
find_string_submatch_index returns the first match for re in s, including submatches. The overall match is s[m[0]:m[1]], the first submatch is s[m[2]:m[3]], and so on. The return value is nil for no match.
The go method
FindStringSubmatchIndex. public function find_submatch(string $b): array-
find_submatch returns the first match for re in b, including submatches. The overall match is m[0], the first submatch is m[1], and so on. The return value is nil for no match.
The go method
FindSubmatch. public function find_submatch_index(string $b): array-
find_submatch_index returns the first match for re in b, including submatches. The overall match is b[m[0]:m[1]], the first submatch is b[m[2]:m[3]], and so on. The return value is nil for no match.
The go method
FindSubmatchIndex. public function literal_prefix(): array-
literal_prefix returns a literal string that must begin any match of the regular expression re. It returns the boolean true if the literal string comprises the entire regular expression.
The go method
LiteralPrefix. public function longest(): void-
longest makes future searches prefer the leftmost-longest match. That is, when matching against text, the regexp returns a match that begins as early as possible in the input (leftmost), and among those it chooses a match that is as long as possible. This method modifies the [Regexp] and may not be called concurrently with any other methods.
The go method
Longest. public function marshal_text(): string-
marshal_text implements [encoding.TextMarshaler]. The output matches that of calling the [Regexp.AppendText] method.
See [Regexp.AppendText] for more information.
The go method
MarshalText. public function match(string $b): bool-
match reports whether the byte slice b contains any match of the regular expression re.
The go method
Match. public function match_reader(object $r): bool-
match_reader reports whether the text returned by the [io.RuneReader] contains any match of the regular expression re.
The go method
MatchReader. public function match_string(string $s): bool-
match_string reports whether the string s contains any match of the regular expression re.
The go method
MatchString. public function num_subexp(): int-
num_subexp returns the number of parenthesized subexpressions in this [Regexp].
The go method
NumSubexp. public function replace_all(string $src, string $repl): string-
replace_all returns a copy of src, replacing matches of the [Regexp] with the replacement text repl. Inside repl, $ signs are interpreted as in [Regexp.Expand].
The go method
ReplaceAll. public function replace_all_func(string $src, callable $repl): string-
replace_all_func returns a copy of src in which all matches of the [Regexp] have been replaced by the return value of function repl applied to the matched byte slice. The replacement returned by repl is substituted directly, without using [Regexp.Expand].
The go method
ReplaceAllFunc. public function replace_all_literal(string $src, string $repl): string-
replace_all_literal returns a copy of src, replacing matches of the [Regexp] with the replacement bytes repl. The replacement repl is substituted directly, without using [Regexp.Expand].
The go method
ReplaceAllLiteral. public function replace_all_literal_string(string $src, string $repl): string-
replace_all_literal_string returns a copy of src, replacing matches of the [Regexp] with the replacement string repl. The replacement repl is substituted directly, without using [Regexp.Expand].
The go method
ReplaceAllLiteralString. public function replace_all_string(string $src, string $repl): string-
replace_all_string returns a copy of src, replacing matches of the [Regexp] with the replacement string repl. Inside repl, $ signs are interpreted as in [Regexp.Expand].
The go method
ReplaceAllString. public function replace_all_string_func(string $src, callable $repl): string-
replace_all_string_func returns a copy of src in which all matches of the [Regexp] have been replaced by the return value of function repl applied to the matched substring. The replacement returned by repl is substituted directly, without using [Regexp.Expand].
The go method
ReplaceAllStringFunc. public function split(string $s, int $n): array-
split slices s into substrings separated by the expression and returns a slice of the substrings between those expression matches.
The slice returned by this method consists of all the substrings of s not contained in the slice returned by [Regexp.FindAllString]. When called on an expression that contains no metacharacters, it is equivalent to [strings.SplitN].
Example:
s := regexp.MustCompile("a*").Split("abaabaccadaaae", 5) // s: ["", "b", "b", "c", "cadaaae"]
The count determines the number of substrings to return: - n > 0: at most n substrings; the last substring will be the unsplit remainder; - n == 0: the result is nil (zero substrings); - n < 0: all substrings.
The go method
Split. public function subexp_index(string $name): int-
subexp_index returns the index of the first subexpression with the given name, or -1 if there is no subexpression with that name.
Note that multiple subexpressions can be written using the same name, as in (?P<bob>a+)(?P<bob>b+), which declares two subexpressions named "bob". In this case, SubexpIndex returns the index of the leftmost such subexpression in the regular expression.
The go method
SubexpIndex. public function subexp_names(): array-
subexp_names returns the names of the parenthesized subexpressions in this [Regexp]. The name for the first sub-expression is names[1], so that if m is a match slice, the name for m[i] is SubexpNames()[i]. Since the Regexp as a whole cannot be named, names[0] is always the empty string. The slice should not be modified.
The go method
SubexpNames. public function unmarshal_text(string $text): void-
unmarshal_text implements [encoding.TextUnmarshaler] by calling [Compile] on the encoded value.
The go method
UnmarshalText.
Binding
- The go type
regexp.Regexp. - Registered by the package
regexp. - Built on
regexp.Regexp. - Satisfies
encoding.TextMarshaler. - Satisfies
encoding.TextUnmarshaler. - Satisfies
fmt.Stringer.