-3
string str = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"376\" height=\"254\" viewBox=\"0 0 376 254\">"

How to extract the value of height?

Anything like height=\"%\"in regex?

Sankarann
  • 2,625
  • 4
  • 22
  • 59

2 Answers2

0

Try this:

string str = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"376\" height=\"254\" viewBox=\"0 0 376 254\">";
Regex regex = new Regex(@"(?<=\bheight="")[^""]*");
Match match = regex.Match(str);
string height = match.Value; // = "254"
mm8
  • 163,881
  • 10
  • 57
  • 88
0

Note that \ is a special escape character. This works:

string str = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"376\" height=\"254\" viewBox=\"0 0 376 254\">";
string temp = Regex.Match(str, "height=\"\\d+\"").Value;   //height=254
int height =Int32.Parse (Regex.Match(temp, "\\d+").Value); //254