Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda