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

155
Vistas
Javascript delete specific text with Regex

I need help with my js regex code.

The text:

9.The average American walks 3,000 to 4,000 steps a day.

From inspect element:

<h3 id="the-average-american-walks-3000-to-4000-steps-a-day">
<span>9.</span> The average American walks 3,000 to 4,000 steps a day.
</h3>

My output:

The average American walks 3,to 4,steps a day.

Expected output:

The average American walks 3,000 to 4,000 steps a day.

My code:

$(".round-number")
            .find("h3")
            .each(function (i, el) {
                let row = $(el).text().replace(/(\s+)/g, " ");
                row = $(el)
                    .text()
                    .replace(/[0-9]+. /g, "")
                    .trim();
                console.log(`${row}`);
                healthArray.push(row);
            });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you want to delete just a single occurrence of the number then you do not need a g flag in the regexp.

Then if it's alway in the beginning of the sentence you can use ^ symbol to make sure regexp only search at the start of the string

You also need to escape . symbol when you use it in regexp, like this - \., otherwise regexp reads it as "any" symbol.

And the last, do trim before applying regex.

Example:

$("h3").each(function (i, el) {
    const row = $(el)
        .text()
        .trim()
        .replace(/^[0-9]+\. /, "");
    console.log(`${row}`);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<h3 id="the-average-american-walks-3000-to-4000-steps-a-day">
  <span>9.</span> The average American walks 3,000 to 4,000 steps a day.
</h3>

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