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

209
Visualizações
Match everything except the digit and space in the very beginning

The target string looks like a number followed by a space and then followed by one or more letters, e.g. 1 Foo or 2 Foo bar.

I can use [^\d\s].+, but it doesn't work for single letters, e.g. 3 A.

What can be done here?

https://regexr.com/6io06

The workaround I use currently is to use replacing instead of matching.

from  \d\s(.+)
to    $1

But as a purist I prefer to use replacing if and only if we don't mean "replace something with nothing". When we need to replace something with nothing, I would prefer to use matching.

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

0

Just remove the square brackets. The square brackets alone indicate "any of this set", so you are matching either \d or \s. When you also add a ^ inside you are not indicating the beginning of the string, but you are negating the set. So, summing up, your regular expression means:

Match a single character that may be everything except a digit and a white space, then match everything.

If you remove the square brackets you will match \d followed by \s, and the ^ symbol will mean "beginning of the string".

/^\d\s(.+)/
about 4 years ago · Juan Pablo Isaza Relatório

0

I prefer using a regex replacement here:

var input = ["1 Foo", "2 Foo Bar", "No Numbers Here"];
var output = input.map(x => x.replace(/^\d+ /, ""));
console.log(output);

about 4 years ago · Juan Pablo Isaza Relatório

0

If I didn't misread your question, this might be what you want:
exclude capture the number and space at the beginning

https://regexr.com/6io1m

(?!^\d+)(?!\s+).*

This matches 1 Foo Bar to Foo Bar and 3 A to A

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