Regular expression REGEX HELP

0

I have an array on the server in Nodejs, I'm going through html files and need to return the value that is in the middle of the span tag using a regular expression how would it look?

{
< span class="filteredAds"> de teste< /span>,

< span class="filteredAds"> de teste23< /span>>

}

It is not known what can come in the middle of the tag after the.

Can someone help me?

    
asked by anonymous 28.01.2017 / 03:49

1 answer

4

Suggestion:

const regex = /<[^\/]*span[^>]*>[^<]+</g;
const subRegex = />([^<]+)</;
const string = '{
< span class="filteredAds"> de teste< /span>,

< span class="filteredAds"> de teste23< /span>>

}';
const conteudo = string.match(regex).map(str => str.match(/>([^<]+)</).pop().trim());
console.log(conteudo); // ["de teste","de teste23"]

The idea is to divide in two steps: capture each span, extract the content. When I use [^<] in regex this means: any character except < .

    
28.01.2017 / 04:38