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

222
Vistas
Match substring with alphanumeric characters (ignoring other substrings) in postgres 11

I have following table in Postres

col1
A02BX
A02BX Other drugs for peptic ulcer and gastro-oesophageal reflux disease (GORD); A03AE Serotonin receptor antagonists

I would like to fetch a substring which is a combination of alphabets and numbers like 'A02BX'. The desired output is:

col1
A02BX
A02BX | A03AE 

I am unable to find any solution to this. Though I tried fetching alphanumeric string using following pattern. But is matching the whole string.

[a-zA-Z0-9]+

The output I am getting is the same as initial table:

A02BX
A02BX Other drugs for peptic ulcer and gastro-oesophageal reflux disease (GORD); A03AE Serotonin receptor antagonists
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can extract all matches using REGEXP_MATCHES and a regular expression that matches alphanumeric substrings between word boundaries that contain at least one letter and at least one digit:

 SELECT REGEXP_MATCHES( 'A02BX Other drugs for peptic ulcer and gastro-oesophageal reflux disease (GORD); A03AE Serotonin receptor antagonists', '\y(?:[AZ]+\d|\d+[AZ])[A-Z0-9]*\y', 'g')

See an SQLFiddle .

Details

  • \y - a word boundary
  • (?:[AZ]+\d|\d+[AZ]) - either 1+ letters and a digit or 1+ digits and then a letter
  • [A-Z0-9]* - 0 or more letters or digits
  • \y - a word boundary.
over 4 years ago · Santiago Trujillo Denunciar

0

Another solution:

select * from t;
                                                         col1                                                          
-----------------------------------------------------------------------------------------------------------------------
 A02BX
 A02BX Other drugs for peptic ulcer and gastro-oesophageal reflux disease (GORD); A03AE Serotonin receptor antagonists
(2 rows)

select col1, regexp_matches(col1, '(\w\d\d\w\w)+', 'g') from t;
                                                         col1                                                          | regexp_matches 
-----------------------------------------------------------------------------------------------------------------------+----------------
 A02BX                                                                                                                 | {A02BX}
 A02BX Other drugs for peptic ulcer and gastro-oesophageal reflux disease (GORD); A03AE Serotonin receptor antagonists | {A02BX}
 A02BX Other drugs for peptic ulcer and gastro-oesophageal reflux disease (GORD); A03AE Serotonin receptor antagonists | {A03AE}
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