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

264
Vistas
How do I get a number based on the numbers on the end of a string?

I have couple of strings which I want to separate out the numbers from last position. If the string doesn't end with a number, 0 or false should be returned.

Here are some examples:

  • string "A1C10" should return 10
  • string "20AX23" should return 23
  • string "15AZC" should return 0 or false
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could use match here:

var inputs = ["A1C10", "20AX23", "15AZC"];
var outputs = inputs.map(x => x.match(/\d+$/) ? x.match(/\d+$/)[0] : "0");
console.log(outputs);

For your new requirement, we can split the input on (?<=\D)(?=\d*$):

var inputs = ["A1C10", "20AX23", "15AZC"];
for (var i=0; i < inputs.length; ++i) {
    var parts = inputs[i].split(/(?<=\D)(?=\d*$)/);
    if (parts.length == 1) parts.push("0");
    console.log(inputs[i] + " => " + parts);
}

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