use strict;
my $str = '<?php
declare(strict_types=1);
namespace Jerry\\QueryBuilder\\Builder;
use Jerry\\Interfaces\\QueryInterface;
use Jerry\\Interfaces\\Statements\\FilterInterface;
use Jerry\\QueryBuilder\\Statements\\Filters\\Where;
class Builder implements Jerry\\Interfaces\\BuilderInterface\\BuilderInterface extends Jerry\\Base\\Stuff
{
/** @var Jerry\\Interfaces\\ConnectorInterface\\Foo */
private $connection;
/** @var \\PDOStatement */
private $statement;
/** @var string */
private $sql;
/** @var QueryInterface */
private $query;
/** @var string */
private $filterSql;
/** @var array */
private $values;
public function __construct(Jerry\\Interfaces\\ConnectorInterface $connection)
{
$this->connection = $connection;
}
public function getResults(QueryInterface $query): array
{
$this->query = $query;
return [];
}
private function buildSql(): void
{
}
private function buildFilters(array $filters = [], string $filterSql = ""): void
{
if (! count($filters)) {
$filters = $this->query->getFilters();
}
$iterator = new \\ArrayIterator($filters);
while ($iterator->valid()) {
$filter = $iterator->current();
$iterator->next();
}
/** @var FilterInterface $filter */
foreach ($filters as $key => $filter) {
unset($filters[$key]);
if ($filter instanceof Where) {
// WHERE foo = bar
$filterSql .= "WHERE ? ? ?";
}
}
}
public function getConnection(): ConnectorInterface
{
$foo = new Jerry\\Interfaces\\ConnectorInterface();
return $this->connection;
}
public function setConnection(ConnectorInterface $connection): void
{
$this->connection = $connection;
}
public function getSql(): string
{
return $this->sql;
}
}';
my $regex = qr`(?:implements|new|@var|extends)\s*(?P<fullNamespace>\\[A-Za-z]+|[A-Za-z]+?(?:\\(?P<class>[A-Za-z]+))+)`p;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html