const regex = new RegExp('(?:implements|new|@var|extends)\\s*(?P<fullNamespace>\\\\[A-Za-z]+|[A-Za-z]+?(?:\\\\(?P<class>[A-Za-z]+))+)', 'g')
const 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;
}
}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions