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

243
Visualizações
Some regular expressions I've been studying

I've found these regex elsewhere:

myString.replace(/^.*\//, '');
myString.replace(/\..*?$/, '');

My question is:

  • do ^ and ?$ make any sense here?

And my interpretation is that ^ isn't relevant, because we are using .* which means "anything".

The second one means replace from the . any character in lazy mode till the end of the string. Which is the same as nothing.

So I'd write them:

myString.replace(/.*\//, '');
myString.replace(/\..*/, '');

But I am not 100% sure as my Regex is quite basic. Ideas?

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

0

Indeed, in the first regular expression the ^ is not really needed. The effect is the same without it.

However, in the second regular expression there is a difference when you omit the ? and the $, because . does not match newline characters (unless you add s as modifier).

See the different results:

let myString = `.this
is multiline`;


console.log(myString.replace(/\..*?$/, ''));

console.log(myString.replace(/\..*/, ''));

about 4 years ago · Juan Pablo Isaza Relatório

0

And my interpretation is that ^ isn't relevant, because we are using .* which means "anything".

Yep, that's the start of the string, but if you're wanting all of the string it has no relevance. Also, go here for a great regex playground.

do ^ and ?$ make any sense here?

To answer the second question, for regex /\..*?$/, the ?$ does not make sense with *, b/c x* means 0 or more of x and x? means 0 or 1 (unless you intentionally wanted 0 or 1 of 0 or more, but doubt that). This is taken directly from the help sheet on regexr.com. enter image description here

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