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

249
Visualizações
Whats wrong with this regex to remove substring?

Trying to strip out the extra addressee from an address string. In the example below, dba bobs is the targeted string to remove.

const NOT_EXTRA_ADDRESSEE = /^(?!.*(attn|co|dba|fka|dept).*\n).*\n/gim;

"bobs burgers dba bobs dinner\n100 Oceanside drive\nnashville, tn 37204"
  .replace(NOT_EXTRA_ADDRESSEE, "");

The above yields:

bobs burgers dba bobs dinner
100 oceanside drive
nashville tn 37204

When the desired is:

bobs burgers
100 oceanside drive
nashville tn 37204

What am I doing wrong? Sometimes the input has a '\n' before the 'dba'.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can simplify your regex to: /\b(attn|co|dba|fka|dept)\b.*/gm

Test here: https://regex101.com/r/TOH9VV/2

const regex = /\b(attn|co|dba|fka|dept)\b.*/gm;

// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\b(attn|co|dba|fka|dept)\\b.*', 'gm')

const str = `bobs burgers dba bobs
100 Oceanside drive
nashville, tn 37204

bobs burgers dba bobs
100 attn Oceanside drive
nashville, tn 37204

bobs burgers dba bobs
100 Oceanside depth drive
nashville, tn fka 37204`;
const subst = ``;

// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);

console.log('Substitution result: ', result);

EDIT: Included suggestion of user Cary Swoveland in the comments.

about 4 years ago · Juan Pablo Isaza 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