Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Easy] Get any value from any website [Regex]

Hey guys this tutorial I will be showing you how to get nearly any value from a website using a regex function.


The function:
Code
Public Shared Function RegexMatch(ByVal Text As String, ByVal Regexstring As String) As MatchCollection
            Dim r As New System.Text.RegularExpressions.Regex(Regexstring)
            Dim matches As MatchCollection = r.Matches(Text.Trim)
            Return matches
    End Function

Usage:
Code
For Each m As Match In RegexMatch(SourceCode, RegexString)
        MsgBox(m.value)
Next

Say we want to get a fresh proxy list from
http://www.xroxy.com/proxylist.php

We want to get the highlighted value here:
Spoiler (Click to View)

It is really simple using this function, so we get the page source either from grabbing it with a webrequest/webclient or just copying the source into a richtextbox, either way.

So here is how it is done, we see before the proxy and port there is this:
Code
proxy:name=XROXY proxy&host=121.52.210.22&port=28889
So to get all values that look like this our function will look something like this:
[Image: 1k5bn]
the ".*" means anything can be there so we grab all strings like that.
Now if we set the value's that we have just grabbed into a richtextbox it should look like this:
Spoiler (Click to View)
We have grabbed the ips but it is a mess, we have to format it using the Split() function, it is quite self explanatory, this is what our function should look like now:
[Image: 1k5dQ]
And we have now successfully extracted the strings in ip/port format.
[Image: 1k59U]

If you have any questions or problems let me know, thanks guys.

[Image: eQhTFwh.gif]

You.should use groups so you do not need to split all the data again.

[Image: HJdK32K_x]
lensert.com is the new screenshot utility, try it out now!
OSX & WINDOWS

(Oct 29, 2012 05:46 AM)marvinn Wrote:  You.should use groups so you do not need to split all the data again.

This. Just use (.*) to create a groups then just use

Code
MsgBox(m.Groups(1).Value)

[Image: 1riOqZa.png]
(Oct 29, 2012 05:51 AM)Weakky. Wrote:  This. Just use (.*) to create a groups then just use

Code
MsgBox(m.Groups(1).Value)

I didn't know about that man, thanks alot.

[Image: eQhTFwh.gif]

You can even use this

Code
var reg = new Regex(proxy&host=(.*)&port=(.*))
foreach(var match in reg.Matches(source))
{
  string ip = match.groups[1].Value;
  string port = match.groups[2].Value;
}

An other tip, check http://regexpal.com
That helps a lot ;)

[Image: HJdK32K_x]
lensert.com is the new screenshot utility, try it out now!
OSX & WINDOWS

Thanks ! I really need this for my Projects in Future Ty so much!
Arrh Regex the one thing that turns my brain to mush thanks for the easy to follow tutorial. 🙂
Pretty cool, thanks for this sharing. Now i'm using the nice 'GetBetween' function, but i've tried this one, and i think to switch to this one! Thanks!
Can you upload again the pictures, please.
If you're just getting value between something such as this, Split would be faster compared to Regex. Regex isn't just about .*, if you're just gonna use .* everywhere then you don't really need to use regex.
Pretty awesome tutorial, thank you for posting it! :D
--
This is kinda useless using both split and regex, it's best to use one or the other. Regex is a good bit faster if you know how to write proper patterns. In this case you should have just used split
(Jan 18, 2013 05:58 AM)Cairns Wrote:  This is kinda useless using both split and regex, it's best to use one or the other. Regex is a good bit faster if you know how to write proper patterns. In this case you should have just used split

This.

Regular split is usually faster performance-wise compared to Regex in most cases, sometimes the split just isn't enough though and we have to use Regex.
I have coded a bot in the past that has harvested up to 1000s of links per page. I tried splitting them each time and it was okay the speed. I used regex to test its speed and found that regex ran much better. But I suppose it can change in most cases
(Jan 18, 2013 06:40 AM)Cairns Wrote:  I have coded a bot in the past that has harvested up to 1000s of links per page. I tried splitting them each time and it was okay the speed. I used regex to test its speed and found that regex ran much better. But I suppose it can change in most cases

That's because you had to call the Split method multiple times, with Regex you just have to call the Matches method once.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by SoldiercrimesJan 14, 2018 01:24 PM 16 478 Jan 14, 2018 01:24 PM
Last Post: Sn0wX
[.NET] by LouisAug 8, 2017 01:35 PM 3 182 Aug 8, 2017 01:35 PM
Last Post: SIM-3327349
[.NET] by polas6Apr 25, 2014 11:10 AM 9 189 Apr 25, 2014 11:10 AM
Last Post: Moen