Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda