Answer the question
In order to leave comments, you need to log in
regexp. What am I missing?
Good evening!
I'm trying to parse html with a reg, but for some reason characters that should not be there get into the group.
What to fix? />(.*?)</gi
And the line is a regular piece of html.
I want to take everything between > and <
I do it like this:
let match = string.match(/>(.*?)</gi);
match.forEach(e => {
console.log(e);
})
Answer the question
In order to leave comments, you need to log in
My solution is the most adequate for my task :)(.*?)</gi/>
It is very strange that you have never heard that regex is not an HTML parsing tool. No need to try to "disassemble the wheel with a comb."
var htmlString = `
<div id="wrapper">
<div class="div">Div 1</div>
<div class="div">Div 2</div>
<div class="div">Div 3</div>
<p class="paragraph">P 1</p>
<p class="paragraph">P 2</p>
<p class="paragraph">P 3</p>
</div>
`;
// Вариант 1
var parser = new DOMParser(),
doc = parser.parseFromString(htmlString, 'text/html');
[].forEach.call(doc.querySelectorAll('body *'), function(el){
console.log(el);
});
// Вариант 2
var tmp = document.createElement('div');
tmp.innerHTML = htmlString;
[].forEach.call(tmp.querySelectorAll('*'), function(el){
console.log(el);
});
you need to provide all combinations of characters that you need.
for example, there is a newline or spaces.
and if so?/>((.*?)|(\s+?))</gi
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question