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

73
Views
Is there a way to do a lazy lookbehind?

I have some HTML text like below.

                <div style="background:#e0dddd; color:#333399; font:9PT 'arial'; padding:10px; margin-left:-30px; ">
                    <div>
                        <strong>Some text here1 </strong><br />
                        2021-08-08                    </div>

                    <div><p>
    Some text here2</p>
</div>
                    <div class="download">
                        <a href="index.php?obj=notice_id=1734">View Detail ...</a>
                    </div>
                </div>
                
                <div style="background:#e2ecf4; color:#333399; font:9PT 'arial'; padding:10px; margin-left:-30px; ">
                    <div>
                        <strong>Some text 3</strong><br />
                        2021-08-06                    </div>

                    <div><p>
    Some BE text 4.</p>
</div>
                    <div class="download">

What I'm trying to capture is the following, basically, from the tag <strong> onwards to the line that has BE in it. It can be case insensitive.

Some text 3</strong><br />
                        2021-08-06                    </div>

                    <div><p>
    Some BE text 4.

I'm using /(?<=<strong>)[\s\S]*?b[ _\/,]?e[\W][\s\S]*?(?=<)/gim but it captures the following.

Some text here1 </strong><br />
                        2021-08-08                    </div>

                    <div><p>
    Some text here2</p>
</div>
                    <div class="download">
                        <a href="index.php?obj=notice_id=1734">View Detail ...</a>
                    </div>
                </div>

                <div style="background:#e2ecf4; color:#333399; font:9PT 'arial'; padding:10px; margin-left:-30px; ">
                    <div>
                        <strong>Some text 3</strong><br />
                        2021-08-06                    </div>

                    <div><p>
    Some BE text 4.

What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I suggest a DOM based solution to iterate over the div elements (at the root level). Then a simple test on the inner text suffices to get the good one:

const parser = new DOMParser();
const doc = parser.parseFromString(`<div id="root">${yourhtml}</div>`, 'text/html');
doc.querySelectorAll('#root > div').forEach(function(el) {
    let text = el.innerText;
    if ( /\bb[^ ,_\/]?e\b/i.test(text) )
        console.log(text); // display in your browser console
});
about 4 years ago · Juan Pablo Isaza 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!