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

160
Visualizações
Write a regular expression that finds strings of the following kind

The task itself looks like this: Given string 'ave a#b a2b a$b a4b a5b a-b acb'. Write a regular expression that finds strings of the following kind: the letters 'a' and 'b' are at the edges, and there is neither a letter nor a number between them.

It's just really hard for me to make sense of it. But I was able to write something like:

'ave a#b a2b a$b a4b a5b a-b acb'.replace(/a\Wb/g, ""),

but it works by replacing only the values I need to output and leaving 'ave a2b a4b a5b acb', but I just need to remove everything except 'a#b a$b a-b'. Can you help me with that?

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

0

You can match all occurrences of the \ba[^\sa-zA-Z0-9]b\b pattern that matches a not preceded with any word char, then any char other than whitespace, letters and digits, and then a b not followed by a word char, and then join the output with a space:

console.log(
  'ave a#b a2b a$b a4b a5b a-b acb'.match(/\ba[^\sa-zA-Z0-9]b\b/g).join(" ")
)

See the regex demo.

Note: if the expected matches occur in between whitespaces or start/end of string, you might need to replace word boundaries with whitespace boundaries, /(?<!\S)a[^\sa-zA-Z0-9]b(?!\S)/g.

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