Need help with my RegEx . Doesn't work

simpleonline12

New member
Sep 29, 2009
191
3
0
I currently have a richtext (GetIt.text) that contain source code from a page. In the below example I am trying to grab anything between the two tags but I'm not sure how to set this up.

My current Regex doesn't return a result.

I am trying to grab anything between the value tags value="anything here"

Any ideas?

Thanks

HTML line that contains the value="" that I need

Code:
<input id="hash" type="hidden" name="humanverify[hash]" value="e5a730f55f6c63196ae50559d6c5fa37" />
This is the code that I am using but it doesn't produce anything.

Code:
   Sub RegExGet()         
' The input string.          
Dim value As String = "name=""humanverify[hash]"" value=""e5a730f55f6c63196ae50559d6c5fa37""

' Invoke the Match method.         
Dim m As Match = Regex.Match(GETIT.Text, _                 
"humanverify[hash]"" value=""([A-Za-z0-9\-]+)""", _                 
RegexOptions.IgnoreCase)          

' If successful, write the group.         
If (m.Success) Then             
Dim key As String = m.Groups(1).Value             
MessageBox.Show(key)         
Else             
MessageBox.Show("We Failed!!!")         
End If     
End Sub
 


Never use regular expressions for html. It's weak, flimsy, awful to read, annoying to write, and shit to debug.

Every language has incredible DOM parsing libraries. From Ruby's Nokogiri to Python's Beautiful Soup to Javascript's Phantom.js to Node's jsdom. html parsers can interpret a document like a browser. They can understand <value=hello>, <value="hello">, <value='hello'>, <value = hello>, <value= hello>, and <value =hello> like a browser can with no additional work. Handling that shit with regex is a waste of life.

Here's the Ruby code that grabs what you want:

Code:
@doc.css_at('#hash').value
I don't know VB libraries, but find out what the popular DOM parsing library is.
 
But to actually answer your question, you need to escape the brackets around [hash]. Else, you're saying "match one character here that's either an h, a, or s"

Change

humanverify[hash]

to

humanverify\[hash\]
 
use stackoverflow.com site. it's full of coding experts which can help you for free.