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

.NET 

Need help with regex code

Quote:>fireup;</td><td class="nw">45fcea35db75fab8ce78e2fccd6b4563&nbsp;</td><td class="nw">


i have the above code in richtext box i would to get the hash 45fcea35db75fab8ce78e2fccd6b4563 by using regex how can i do that.Thanks
MsgBox(System.Text.RegularExpressions.Regex.Match(">fireup;</td><td class=""nw"">45fcea35db75fab8ce78e2fccd6b4563&nbsp;</td><td class=""nw"">", """>(.*?)&").Groups(1).Value)
(Jun 23, 2015 05:02 AM)Only3 Wrote:  MsgBox(System.Text.RegularExpressions.Regex.Match(">fireup;</td><td class=""nw"">45fcea35db75fab8ce78e2fccd6b4563&nbsp;</td><td class=""nw"">", """>(.*?)&").Groups(1).Value)

Your code works fine but i changed the code like this but its not working.
Quote:TextBox1.Text = System.Text.RegularExpressions.Regex.Match(RichTextBox2.Text, """>(.*?)&").Groups(1).Value



RichTextBox2.Text contains some website source....Thanks for the help.
System.Text.RegularExpressions.Regex.Match(RichTextBox2.Text, "class=""nw"">(.*?)&").Groups(1).Value
Well If the string will ALWAYS start and ALWAYS end with the same you could go the easy way and do this:

Code
Dim i as String = ">fireup;</td><td class="nw">45fcea35db75fab8ce78e2fccd6b4563&nbsp;</td><td class="nw">"
i = i.Replace(">fireup;</td><td class="nw">", "")
i = i.Replace("&nbsp;</td><td class="nw">", "")
Msgbox("Your Final String Will Be :  " & i)
Code
Dim hash As String = Regex.Match(RichTextBox2.Text, ">fireup;<\/td><td\sclass=""nw"">(.*);<\/td><td\sclass=""nw"">").Groups(1).Value

Is it possible to provide us with the full source code? That way we can alter the regex pattern to fit the source code better.
You shouldn't really be using Regex to parse a HTML document. Regex is a terribly inefficient way to parse HTML. If computers had the capability to cry then your computer would cry each time you attempted to parse HTML with Regex.

This is Regex abuse. Search up on Finite State Automatons, you'll see why you should never try to parse HTML with Regex and how inefficient it can be. Rather, you should use a HTML Parser such as HTMLAgilityPack.

Regex was designed to match Regular Expressions and not context free languages like HTML.
(Jun 23, 2015 11:37 AM)+Haze Wrote:  You shouldn't really be using Regex to parse a HTML document. Regex is a terribly inefficient way to parse HTML. If computers were able to cry then your computer would cry each time you attempted to parse HTML with Regex.

This is Regex abuse. Search up on Finite State Automatons, you'll see why you should never try to parse HTML with Regex. Rather, you should use a HTML Parser such as HTMLAgilityPack.

Regex was designed to match Regular Expressions and not context free languages like HTML.

who say 😊 some dumb guy from stackoverflow
Dont (Click to View)
(Jun 23, 2015 11:45 AM)Only3 Wrote:  who say 😊 some dumb guy from stackoverflow
Dont (Click to View)

Anybody that knows what they're doing would recommend you not to parse HTML with Regex. While there was a guy I worked with that got roasted by two of my senior co-workers simply because he suggested using to scrape data using a regex exp on a html page.
I mean sure it works, but it's not recommended to use.

Using Regex to parse HTML is just as bad as using Me.CheckForIllegalCrossThreadCalls = False

Read up on the theory of finite state automatons, and you'll see why Regex shouldn't be parsed with them.
(Jun 23, 2015 11:49 AM)+Haze Wrote:  Anybody that knows what they're doing would recommend you not to parse HTML with Regex. While there was a guy I worked with that got roasted by two of my senior co-workers simply because he suggested using to scrape data using a regex exp on a html page.
I mean sure it works, but it's not recommended to use.

Using Regex to parse HTML is just as bad as using Me.CheckForIllegalCrossThreadCalls = False

Read up on the theory of finite state automatons, and you'll see why Regex shouldn't be parsed with them.

Doesn't it depend how much you're scraping? If you just want one string in an html source, wouldn't using regex be acceptable? I thought like the HTML Agility Pack was only for scraping large amounts. If I'm wrong, please correct me. I'm still learning about all this stuff so I wouldn't be surprised if I was wrong.
(Jun 23, 2015 11:55 AM)LUOIdeRentA Wrote:  Doesn't it depend how much you're scraping? If you just want one string in an html source, wouldn't using regex be acceptable? I thought like the HTML Agility Pack was only for scraping large amounts. If I'm wrong, please correct me. I'm still learning about all this stuff so I wouldn't be surprised if I was wrong.

Well that's the thing, Regex is a quick fix for parsing HTML. Ideally you should be using HTMLAgilityPack regardless of how much you're intending to scrape. It's good to put good practice into use as much as possible. That's like saying, "I should only use Delegates and Invoking when multi threading when I'm doing big tasks, but when I'm doing a quick task I should use "Me.CheckForCrossThreadCalls = False".

See how that mentality is bad?

Also, Parsing a HTML file with HTMLAgilityPack is so sweet, it's so much nicer and easier to use, and at the end of the day it's easier to write maintainable code with it. Any dev can hop into your code straight from where you left with ease.
(Jun 23, 2015 12:01 PM)+Haze Wrote:  Well that's the thing, Regex is a quick fix for parsing HTML. Ideally you should be using HTMLAgilityPack regardless of how much you're intending to scrape. It's good to put good practice into use as much as possible. That's like saying, "I should only use Delegates and Invoking when multi threading when I'm doing big tasks, but when I'm doing a quick task I should use "Me.CheckForCrossThreadCalls = False".

See how that mentality is bad?

Also, Parsing a HTML file with HTMLAgilityPack is so sweet, it's so much nicer and easier to use, and at the end of the day it's easier to write maintainable code with it. Any dev can hop into your code straight from where you left with ease.

I see, thanks for that comment, I learned a lot from that. I shall definitely look into using the HTMLAgilityPack more. I also understand and agree with you completely on the example that you gave about multithreading.
😊 https://code.msdn.microsoft.com/VBASPNET...e-f6ace456
(Jun 23, 2015 02:36 PM)Only3 Wrote:  😊 https://code.msdn.microsoft.com/VBASPNET...e-f6ace456

What's that suppose to prove?

Not too long ago, I applied for a job at a big software company. To verify my account the company sent me a link and both my username and password I had just registered with in plaintext. This obviously means my password is not safely stored (not hashed, though it could be encrypted).

But, does that also mean that just because a huge cooperation does something that we should follow the same princepals?

Look at Adobe, before they used to store their passwords in plain text, does that mean we should also store ours in plain text just because adobe is doing so?
(Jun 23, 2015 02:43 PM)+Haze Wrote:  What's that suppose to prove?

Not too long ago, I applied for a job at a big software company. To verify my account the company sent me a link and both my username and password I had just registered with in plaintext. This obviously means my password is not safely stored (not hashed, though it could be encrypted).

But, does that also mean that just because a huge cooperation does something that we should follow the same princepals?

Look at Adobe, before they used to store their passwords in plain text, does that mean we should also store ours in plain text just because adobe is doing so?

To be fair adobe are not MS and MS invented the .net library so if regex is fine with them its fine with me :)

Edit: Also I used to work for a large company as vb.net dev( I am now freelance as a c# developer) , The boss said he dose not care what methods are used as long as it dose the job and works, Its good code..

As many other business's are run time is the key factor and keeping to the SLA agreements are the only true thing to worry about.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by PringlesJun 13, 2014 12:59 PM 22 324 Jun 13, 2014 12:59 PM
Last Post: SIM-1456245
[.NET] by polas6Apr 25, 2014 11:10 AM 9 191 Apr 25, 2014 11:10 AM
Last Post: Moen
[.NET] by BrokeosJan 5, 2014 02:17 PM 3 189 Jan 5, 2014 02:17 PM
Last Post: Ace of Spades