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

95
Vistas
How to find substring ignoring the data inside comment

I am trying to find substring from an HTML string by ignoring the commented code. I have tried something like below but it is nor giving me expected result , Any pointer will be really appreciated.

let a = `<div data-bind="attr: {id: componentId + 'MasterDetailContainer'}"
     style="height: 100%; width: 100%">

    <!-- master --> <!-- Bug 31793483 adding aria label -->
    <div role="navigation" data-bind="attr: {id: componentId + 'MasterDetailStartDrawer'}">`;
 
let databindIndex =a.indexOf('data-bind');
//Get all the data till next valid starting tag ignoring commented code
let data =a.indexOf(/<\w\s/g,databindIndex);
console.log(data);

Expected output

`data-bind="attr: {id: componentId + 'MasterDetailContainer'}"
         style="height: 100%; width: 100%">
    
        <!-- master --> <!-- Bug 31793483 adding aria label -->`
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use something like this:

const text = `<div data-bind="attr: {id: componentId + 'MasterDetailContainer'}"
     style="height: 100%; width: 100%">

    <!-- master --> <!-- Bug 31793483 adding aria label -->
    <div role="navigation" data-bind="attr: {id: componentId + 'MasterDetailStartDrawer'}">`

const pattern = /data-bind[^\>]*>[\s\S]*<!--[\s\S]*?-->/

const result = text.match(pattern)

console.log({result})

about 4 years ago · Santiago Trujillo 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