malefic 48 Posted August 17, 2011 Report Share Posted August 17, 2011 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: 12345678AF45260F2F3429203ED2372F3429203A62FA5420293AF229372612 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 Quote Link to post Share on other sites
Eddie Waller 158 Posted August 17, 2011 Report Share Posted August 17, 2011 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: 12345678AF45260F2F3429203ED2372F3429203A62FA5420293AF229372612 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 Quote Link to post Share on other sites
malefic 48 Posted August 17, 2011 Author Report Share Posted August 17, 2011 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 Quote Link to post Share on other sites
Frank 177 Posted August 17, 2011 Report Share Posted August 17, 2011 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 Quote Link to post Share on other sites
malefic 48 Posted August 17, 2011 Author Report Share Posted August 17, 2011 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? Quote Link to post Share on other sites
Praney Behl 314 Posted August 18, 2011 Report Share Posted August 18, 2011 I would try to build a Regex creator for Ubot and share around, when I get time next. 1 Quote Link to post Share on other sites
JohnB 255 Posted August 18, 2011 Report Share Posted August 18, 2011 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 Quote Link to post Share on other sites
malefic 48 Posted August 18, 2011 Author Report Share Posted August 18, 2011 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 Thanks to everyone who responded! Quote Link to post Share on other sites
JohnB 255 Posted August 19, 2011 Report Share Posted August 19, 2011 Glad I could contribute to the cause Quote Link to post Share on other sites
CreativeWurks 9 Posted September 15, 2011 Report Share Posted September 15, 2011 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. Quote Link to post Share on other sites
Security 17 Posted June 4, 2012 Report Share Posted June 4, 2012 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).. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.