Link to home
Start Free TrialLog in
Avatar of Dinesh Kumar
Dinesh KumarFlag for India

asked on

regex (get all inputs of form)

How can I fetch the values of each input from the attached HTML using regular expression in c#.

please provide the code also and you need to explain it also in simple words. it will be much appreciated.

Avatar of guvera
guvera
Flag of India image

Avatar of Dinesh Kumar

ASKER

please provide the working code!
Hi,

May i know how is your input?

Because the regular expression you need to match the values and capture it.

Thanks
sorry it is attached now.
inputs.txt
suggestion:
I think if we can pick only all values i.e
value="2.0"
value="4314229999999913"
value="13"

and then looping it should do the work. is n't that guvera?
before try this one add namespace

using System.Text.RegularExpressions;


http://msdn.microsoft.com/en-us/library/30wbz966%28VS.71%29.aspx
String regexPattern = "value='[^*']";
                MatchCollection regexMatches = Regex.Matches(secondResponseFromServer, regexPattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase);

 it matches only beginning single character of each value.
Hi Dinesh,

Certainly, using Regular Expression is one approach, however, that would involve a lot of hard work creating the regex. I would recommend that you use the HTML Agility Pack, which you can download from here:

http://htmlagilitypack.codeplex.com/

It does a lot of the heavy lifting that you need to do in order to parse the HTML.

Hope that helps!
If u wish to match all your values, use
String regexPattern = "value='[a-zA-Z0-9.-:/]";
ASKER CERTIFIED SOLUTION
Avatar of Shahan Ayyub
Shahan Ayyub
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This should give you just the value of each "value":
using System.Text.RegularExpressions;

Regex reg = new Regex("(?<=INPUT[^>]*?value=[\"']?)[^\"'>]*");
MatchCollection matches = reg.Matches(source_string);

foreach (Match m in matches)
{
    //m.Value holds the matched text
}

Open in new window

Kaufmed, please explain your regex!
keen to accept multiple solutions.

kaufmed, please make these clear:
@"value='.*'"
why @ here?

good Shahan_Developer! can you make clear RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline ?
kaufmed and Shahan_Developer, waiting for your post!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial