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
?
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
?
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"
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