Find attribute value with regex

2

I get a string from an RSS feed, the part of which is of interest:

<table feedtag="divinegoblin" ...

Each piece of the feed will always have this feedtag="..." attribute. I would like to get the value of this attribute (in the divinegoblin case) with Regex. I know almost nothing about Regex, I was trying to get it using (feedtag) , but I do not know how to get what's ahead (in this case what's inside the quotation marks). How can I do it?

    
asked by anonymous 14.06.2017 / 02:29

2 answers

3

The simplest way you can use it is like this:

feedtag="([^"]*)"

In this way it takes everything inside the quotation marks after a feedtag=

See it working: link

    
14.06.2017 / 03:45
1

an example using regex , returning only the value within the quotes through group capture .

var a = '<table feedtxag="wesas" feedtag="divinegoblin"';
var conteudo;
conteudo = a.substring(a.indexOf('feedtag="') + 'feedtag="'.length, a.indexOf('"', a.indexOf('feedtag="') + 'feedtag="'.length));
console.log("SUBSTRING: " + conteudo);

var regexResultado = a.match(/feedtag="\s*([^"]*)\s*"/)[1];
console.log("REGEX: " + regexResultado);
    
14.06.2017 / 14:46