Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
How to make an regexp request with TYPO3 queryBuilder

I currently have a big list of entries in my TYPO3 Ext that causes the Site to have pretty poor loading times, so i want to split up the Entry list alphabetically. For that I'm using the queryBuilder to select only those entries, that start either with an a, b, c and so on. But im stuck now when it comes to numbers and special chars. I found this: MySQL - If It Starts With A Number Or Special Character which is exactly what I need. But I have no clue how to make an REGEXP in the queryBuilder. Can someone help?

TYPO3 version is 10.4.6

Thanks in advance

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I would suggest to use LIKE to find strings starting with a given character.

Using LIKE

$firstCharacter = 'A';

$q = GeneralUtility::makeInstance(ConnectionPool::class)
       ->getQueryBuilderForTable('mytable');
$q->select('field')
  ->from('mytable')
  ->where(
    $q->expr()->orX(
      $q->expr()->like(
        'field',
        $q->quote(strtolower($firstCharacter) . '%')
      ),
      $q->expr()->like(
        'field',
        $q->quote(strtoupper($firstCharacter) . '%')
      );

upper/lower case could be left out of course if the DBMS is case insensitive.

Using REGEXP

@eliashaeussler gave a good example for that.

While LIKE is supported by Doctrine dbal, REGEXP is not. You would lose cross-DBMS compatiblity. This is probably fine if you target a specific site but should not be used in public extensions of course.

over 4 years ago · Santiago Trujillo Denunciar

0

Maybe something like this works for you:

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
$result = $queryBuilder->select('*')
    ->from($tableName)
    ->where(
        $queryBuilder->expr()->comparison(
            $queryBuilder->quoteIdentifier($fieldName),
            'NOT REGEXP',
            $queryBuilder->createNamedParameter('^[[:alpha:]]')
        )
    )
    ->execute()
    ->fetchAll();

This creates a query like this (assuming $tableName = 'foo' and $fieldName = 'baz'):

SELECT `foo`.*
FROM `foo`
WHERE `foo`.`baz` NOT REGEXP '^[[:alpha:]]'

Reference: https://github.com/TYPO3/TYPO3.CMS/blob/10.4/typo3/sysext/core/Classes/Database/Query/Expression/ExpressionBuilder.php#L97-L100

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda