package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?:implements|new|@var|extends)\s*(?P<fullNamespace>\\[A-Za-z]+|[A-Za-z]+?(?:\\(?P<class>[A-Za-z]+))+)`)
var 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;
}
}`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
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 Golang, please visit: https://golang.org/pkg/regexp/