Need RegEx help with my expression. Currently Not working.

simpleonline1234

Junior Member
Joined
Jan 26, 2010
Messages
170
Reaction score
13
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
 
Hi,
[ and ] are operators in regex, so you have to escape them with \.
Code:
Sub RegExGet()


        Dim value As String = "name=""humanverify[hash]"" value=""e5a730f55f6c63196ae50559d6c5fa37"""
        Dim m As Match = Regex.Match(value, "humanverify\[hash\]"" value=""([A-Za-z0-9\-]+)""", RegexOptions.IgnoreCase)
        
    End Sub
 
Damn that was quick....thanks it works like a charm..One up for you my friend.
 
Maybe it can help, in Delphi for this kind of job I use a simple parser function :
Code:
function Parse(T_, ForS, _T: string): string;var
  a, b: integer;
begin
  Result := '';
  if (T_ = '') or (ForS = '') or (_T = '') then
    Exit;
  a := Pos(T_, ForS);
  if a = 0 then
    Exit
  else
    a := a + Length(T_);
  ForS := Copy(ForS, a, Length(ForS) - a + 1);
  b := Pos(_T, ForS);
  if b > 0 then
    Result := Copy(ForS, 1, b - 1);
end;

This function will return the value contained between two tags (strings).

So, you'll use it like that :
Code:
var
  in, out: string;
begin
  in := '<input id="hash" type="hidden" name="humanverify[hash]" value="e5a730f55f6c63196ae50559d6c5fa37" />';
  out := Parse('<input id="hash" type="hidden" name="humanverify[hash]" value="', in, '" />');
end;

It's in Delphi but I think it's easy to convert in VB...

Beny
 
Back
Top