1

So I have a token, and it looks for instance like asdkl3njkln1mlnmlaskjenr&email=example@gmail.com&asd345d&password=example&asd986asn

The strings before/after &email=example@gmail.com& and &password=example& change constantly on each page load.

All I need is for a user to input his username/password to a textbox to check on order status/etc. How would I get the email address and password from the token?

What I tried in VB.NET was:

Dim token As String = Regex.Match(htmlPage, "(?\<email=\)+user+(?=\\&\)").Groups(0).Value

But that doesn't seem to work.

htmlpage being the login page for the site that has the order statuses, which is downloaded in order for Regex to get in between those strings, in the token.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Khasym
  • 19
  • 4
  • 1
    Don't use a regular expression for this. [Use a query string parser](https://msdn.microsoft.com/en-us/library/ms150046%28v=vs.110%29.aspx) (if it is indeed a query string as it looks like). – user2864740 Apr 04 '15 at 02:23
  • @user2864740 is right. Here's an example that will demonstrate how: http://stackoverflow.com/questions/12781829/vb-net-parse-query-string-to-array – Seamus Apr 04 '15 at 02:29

1 Answers1

0

While the best answer is using a query parser, I would like to explain the problem with the current regex. The main point is that you over-escaped characters and used a malformed look-behind.

Correct regex will look like this: (?<=email=)[^&]+(?=&)

Here is a sample program with a fixed working regex:

Imports System.Text.RegularExpressions
Module VBModule

Sub Main()
    Dim htmlPage As String = "asdkl3njkln1mlnmlaskjenr&email=example@gmail.com&asd345d&password=example&asd986asn"
    Dim token As String = Regex.Match(htmlPage, "(?<=email=)[^&]+(?=&)").Value
    Console.WriteLine(token)
End Sub
End Module

Output: example@gmail.com

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563