?
Solved

regex (get all inputs of form)

Posted on 2010-11-10
17
Medium Priority
?
432 Views
Last Modified: 2012-08-14
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
Comment
Question by:Dinesh Kumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
  • +2
17 Comments
 
LVL 8

Expert Comment

by:guvera
ID: 34109419
0
 

Author Comment

by:Dinesh Kumar
ID: 34109539
please provide the working code!
0
 
LVL 8

Expert Comment

by:guvera
ID: 34109584
Hi,

May i know how is your input?

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

Thanks
0
Independent Software Vendors: 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!

 

Author Comment

by:Dinesh Kumar
ID: 34109603
sorry it is attached now.
inputs.txt
0
 

Author Comment

by:Dinesh Kumar
ID: 34109703
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
 
LVL 8

Expert Comment

by:guvera
ID: 34109739
0
 
LVL 8

Expert Comment

by:guvera
ID: 34109743
before try this one add namespace

using System.Text.RegularExpressions;


http://msdn.microsoft.com/en-us/library/30wbz966%28VS.71%29.aspx
0
 

Author Comment

by:Dinesh Kumar
ID: 34109831
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
 
LVL 8

Expert Comment

by:guvera
ID: 34110049
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
 
LVL 4

Expert Comment

by:daletian
ID: 34110134
If u wish to match all your values, use
String regexPattern = "value='[a-zA-Z0-9.-:/]";
0
 
LVL 19

Accepted Solution

by:
Shahan Ayyub earned 936 total points
ID: 34114920
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34115733
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
 

Author Comment

by:Dinesh Kumar
ID: 34117944
Kaufmed, please explain your regex!
0
 

Author Comment

by:Dinesh Kumar
ID: 34117972
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
 

Author Comment

by:Dinesh Kumar
ID: 34119407
kaufmed and Shahan_Developer, waiting for your post!
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 464 total points
ID: 34119965
>> 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
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 936 total points
ID: 34121213
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question