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

85
Views
How to make RegExps ignore some tags

I want to make my regular expression ignore if there are any tags between two characters. I thought of getting the child node list and defining some strings that corresponding start and finish tags of that nodes but I couldn't solve how to make my regular expression ignore that tags.

For example, I've listed the insert tags and made this array

let tags = ["<div class='cl'>","</div>","<span class='sp'>","</span>"]

The string in which I want to search my regular expression

let str = "The people <div class='cl'>in StackOverflow <span class='sp'> are very helpful.</span></div>"

And I want to find "people in StackOverflow" in this text to get the start and finish indexes. How can I do that?

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

0

If the regex matches both the tags and what's not in a tag.
Then you can capture and keep what's not in a tag.

/<[^>]+>|([^<>]+)/g

const str = "The people <div class='cl'>in StackOverflow <span class='sp'> are very helpful.</span></div>"

let re = /<[^>]+>|([^<>]+)/g;

let result = str.replace(re,'$1');

console.log(result);

let positions = [];
while (m = re.exec(str)) {
  if(m[1]) positions.push([m.index, re.lastIndex])
}
console.log(positions);

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!