Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!