-1

how could I get value from regexp?

var str = '<tag>VALUE</tag>'; // VALUE
Debra Maddux
  • 841
  • 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
  • 310,407
  • 61
  • 442
  • 435
2

use groups:

var m = /<[^>]+>([^<]*)<\/[^>]+>/.exec('<tag>VALUE</tag>');
var s = m[1]
kelloti
  • 8,373
  • 4
  • 44
  • 78
0

Matching anything between > and <

"(?<=\>)(.*?)(?=\<)"
Peter Kelly
  • 13,853
  • 6
  • 52
  • 62