Filter string REGEX C #

4

I have a string that returns all the contents of a html page.

On this page, you have the following line:

<input style="width: 2.3em;" id="nacional" value="3,48" type="text">

I need only the value that is in value , that is, 3,48 , remembering that this value changes automatically every day.

How can I filter this line and get the value?

    
asked by anonymous 11.05.2016 / 03:41

2 answers

3

I made a Regexr with your default . The regular expression is:

value=\"([\d,]+)\"

In C # it gets a little different.

var regex = new Regex(@"value=""([\d,]+)""");

Once this is done, simply select group 1 (group 0 is the entire match found). That is:

var match = regex.Match("<input style=\"width: 2.3em;\" id=\"nacional\" value=\"3,48\" type=\"text\">");
Console.WriteLine(match.Groups[1].Value);

I made a Fiddle .

    
11.05.2016 / 04:55
1

Here is an example that returns any double-quoted or apostrophe character within the value attribute.

value=['"](.*?)['"]
    
11.05.2016 / 04:31