-1

how could I get value from regexp?

var str = '<tag>VALUE</tag>'; // VALUE
Debra Maddux
  • 861
  • 1
  • 7
  • 5

3 Answers3

3

If your string is really that simple, you could simply get rid of the tags:

var str = '<tag>VALUE</tag>';

str = str.replace(/<tag>|<\/tag>/g,'');

If it is actually more complex or variable, then a regex may not be the way to go.

user113716
  • 318,772
  • 63
  • 451
  • 440
2

use groups:

var m = /<[^>]+>([^<]*)<\/[^>]+>/.exec('<tag>VALUE</tag>');
var s = m[1]
kelloti
  • 8,705
  • 5
  • 46
  • 82
0

Matching anything between > and <

"(?<=\>)(.*?)(?=\<)"
Peter Kelly
  • 14,253
  • 6
  • 54
  • 63