Jump to content
UBot Underground

Searching for matches - regex headaches!


Recommended Posts

Hey guys - simple regex makes my eyes bleed and I have been at the following for a few hours with no success.

 

I have a page of text which contains 8 character strings that I want to rip out.

The strings have to be exactly 8 characters in length, start with the number 2 and have at least one character between A and F in there.

 

I have tried a few different ways, the latest being ^2[A-Fa-f0-9]{7} but it matches the first 8 characters out of any string that starts with a two.

 

For example, in the page of text the following strings are appearing:

 

12345678

AF45260F

2F3429203ED237

2F342920

3A62FA54

20293AF2

29372612

 

I want ubot to select only 2 strings: 2F342920 & 20293AF2 and then add them to a list.

 

Any pointers appreciated - since last night I have been trying to read up on regex and only appear to get myself more confused!

 

Thanks :)

Link to post
Share on other sites

Hey guys - simple regex makes my eyes bleed and I have been at the following for a few hours with no success.

 

I have a page of text which contains 8 character strings that I want to rip out.

The strings have to be exactly 8 characters in length, start with the number 2 and have at least one character between A and F in there.

 

I have tried a few different ways, the latest being ^2[A-Fa-f0-9]{7} but it matches the first 8 characters out of any string that starts with a two.

 

For example, in the page of text the following strings are appearing:

 

12345678

AF45260F

2F3429203ED237

2F342920

3A62FA54

20293AF2

29372612

 

I want ubot to select only 2 strings: 2F342920 & 20293AF2 and then add them to a list.

 

Any pointers appreciated - since last night I have been trying to read up on regex and only appear to get myself more confused!

 

Thanks :)

 

You could try adding \b to the end of your regex like ^2[A-Fa-f0-9]{7}\b

Link to post
Share on other sites

You could try adding \b to the end of your regex like ^2[A-Fa-f0-9]{7}\b

 

 

Thanks Eddie - the \b solved the string length thing....ended up using 2[A-Fa-f0-9]{7}\b.

For some reason using the ^ at the start just didn't want to work!

 

Now to ensure there is at least one letter in the string....more headaches ahead I think :D

Link to post
Share on other sites

malefic,

 

Have you taken a look into the part of the forum dedicated to regular expressions. I've personally posted tutorials to help anyone get the hang of things.

 

I have to tell you, learning regex is critical as a programmer, even in ubot. It may be a complicated tool to learn (and I'm still learning), but it makes programming tasks that are pretty much impossible, very easy.

 

I'd take some time and learn this beastie inside and out.

 

Frank

Link to post
Share on other sites

Frank - I have indeed had a look in the RegEx 101 forum....however, maybe my brain is too old to take it all in :)

I am starting to understand that learning regex is an uphill struggle but I can also see the power they have.

 

I have a day off tomorrow that is to be set aside for a regex crash course :)

 

Thanks!

 

*EDIT*

Another thing that confuses me is that if I get a regex to work using http://www.gskinner.com/RegExr/, I then copy and paste the regex into Ubot and it doesn't work. Is there something special I need to do for regex to work properly?

Link to post
Share on other sites

Frank - I have indeed had a look in the RegEx 101 forum....however, maybe my brain is too old to take it all in :)

I am starting to understand that learning regex is an uphill struggle but I can also see the power they have.

 

I have a day off tomorrow that is to be set aside for a regex crash course :)

 

Thanks!

 

*EDIT*

Another thing that confuses me is that if I get a regex to work using http://www.gskinner.com/RegExr/, I then copy and paste the regex into Ubot and it doesn't work. Is there something special I need to do for regex to work properly?

 

It matters what "flavor" the test engine uses...for example, rubular.com uses ruby, so you will run into that same problem occasionally. For example, the ^ doesn't work in rubular but when put in my bot (this was just yesterday ironically), it worked. The "flavor" you are looking to use in UBot is .NET. I hope that helps.

 

John

 

 

 

Link to post
Share on other sites

It matters what "flavor" the test engine uses...for example, rubular.com uses ruby, so you will run into that same problem occasionally. For example, the ^ doesn't work in rubular but when put in my bot (this was just yesterday ironically), it worked. The "flavor" you are looking to use in UBot is .NET. I hope that helps.

 

John

 

John - Thanks for the reply, that makes it a bit easier for me.

To be honest, if my remaining two braincells had thought about it, with ubot being a Windows app, it is of course going to be a .Net thing!

 

Today is a new day and it contains lots of regex :D

 

Thanks to everyone who responded!

Link to post
Share on other sites
  • 4 weeks later...

I found a few places that help with learning a little about Regex. I am looking at Regex now... I see how useful this can be. P.I.T.A. to learn.. but I'm sure it will help. Sure which there was one universal "flavor" for all of it. Anyhow, check out w w w(dot)added b y t e s(dot)com/cheat-sheets/regular-expressions-cheat-sheet-version-1/

 

Might help out some folks that don't know much about Regex. They have a PNG and PDF version that you can print out, and look at code.

 

Also, you can try the w w w (dot) t x t 2 r e (dot) com site.. I'm looking there too.

Link to post
Share on other sites
  • 8 months later...
you are looking to use in UBot is .NETJohn

 

Thank you so much John.. was looking for this answer every where (even posted in the wrong section of this forum http://ubotstudio.com/forum/index.php?/topic/10427-regular-expression-engines/ Dont know how to take it off)..

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...