Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

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.

0
Dinesh Kumar
Asked:
Dinesh Kumar
  • 7
  • 5
  • 2
  • +2
3 Solutions
 
guveraCommented:
0
 
Dinesh KumarAuthor Commented:
please provide the working code!
0
 
guveraCommented:
Hi,

May i know how is your input?

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

Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dinesh KumarAuthor Commented:
sorry it is attached now.
inputs.txt
0
 
Dinesh KumarAuthor Commented:
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?
0
 
guveraCommented:
before try this one add namespace

using System.Text.RegularExpressions;


http://msdn.microsoft.com/en-us/library/30wbz966%28VS.71%29.aspx
0
 
Dinesh KumarAuthor Commented:
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.
0
 
guveraCommented:
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!
0
 
daletianCommented:
If u wish to match all your values, use
String regexPattern = "value='[a-zA-Z0-9.-:/]";
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
Please check this as well:





String regexPattern = "value=\".*\"";
MatchCollection regexMatches = Regex.Matches(secondResponseFromServer, regexPattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase);

Open in new window

0
 
käµfm³d 👽Commented:
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

0
 
Dinesh KumarAuthor Commented:
Kaufmed, please explain your regex!
0
 
Dinesh KumarAuthor Commented:
keen to accept multiple solutions.

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

good Shahan_Developer! can you make clear RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline ?
0
 
Dinesh KumarAuthor Commented:
kaufmed and Shahan_Developer, waiting for your post!
0
 
käµfm³d 👽Commented:
>> kaufmed , please make these clear :
>> @" value=' . *'" >
> why @ here?

I don't see where I used it, but the @ in front of a string literal turns the string into a raw string where backslashes are literal characters and not the escape character that they normally are.

Pattern explanation : ( ? < = I N P U T [ ^ > ] * ? v a l u e = [ \ " ' ] ? ) [ ^ \ " ' > ] *

(?<= ... )       Positive lookbehind; find this, but don't consider it part of the match
INPUT          literal
[^>]*?           zero or more ( * ) of any chacter NOT ( [^ ... ] ) a closing bracket ( > ). Non-greedy ( ? ), so stop searching at the first match
value=          literal
["']?              zero or one ( ? ) of either ( [ ... ] ) a single or double quote. Note, the backslash is an escape for the doble quote and not part of the pattern
[^"'>]*          zero or more ( * ) of any character NOT ( "[^ ... ] ) a single or double quote or a closing bracket. Again, the double quote is escaped
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
Hi!

Does it helps you to understand the meaning of the two keywords you pointed out:
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions%28VS.95%29.aspx

I just changed the pattern from your existing pattern of ID: 34109831:

This can also work:

     String regexPattern = "value=\".*\"";
     MatchCollection regexMatches = Regex.Matches(secondResponseFromServer, regexPattern);
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now