Latest Uploads
Extraterre ... .0.1 (zip)

dantheman363

Monty Teas ... Screenie 1

steve_ancell

Santa Clau ... ed his bag

waroffice

manic_platdude.png

spinal

Tetris Clone

steve_ancell

Super blues bros.

spinal

Forum Home

Regular Expression help

UserMessage
Posted : Friday, 07 December 2007, 20:49 | Permalink | Mark Here
JL235


WW Entries : 7
I'm having trouble writing a regular expression, because I think it's impossible. I believe it might be more of a job for a grammer, but I have a different (but worse) solution lined up if I can't do it with a regular expression. What I want to do is have a string of characters, any length, of lets say b's and a's. I am trying to write an expression which will match a minimum of 8 a's anywhere within 28 consecutive characters, within that string.

The only way I can think of doing this would be to type out every combination of a's and b's with an | between each one. Is there a proper way?

And this actually has nothing to do with Ruby (I'm writing this in Java). We just don't have a general coding section.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Saturday, 08 December 2007, 00:53 | Permalink | Mark Here
Dabz


WW Entries : 1
Dont know anything about Ruby, but here's a rough and ready example I made ages ago for Blitz:-

-->

That might shed some light!

Dabz

-----
Mac OS X 10.6.6 (VM: WinXP3)
3.2 Ghz Intel Core (Blimey) i3
4 GB 1333 MHz DDR3
ATI Radeon HD 5670 512MB GPU
Posted : Saturday, 08 December 2007, 04:03 | Permalink | Mark Here
Jayenkai


WW Entries : 103
Tip : When dealing with RegEx, I tend to load up Programmer's Notepad and use the Find panel, which contains a RegEx function.

AAAAAAA+A = A group of 8 or more A's

-----
Posted : Saturday, 08 December 2007, 08:39 | Permalink | Mark Here
JL235


WW Entries : 7
Thanks MaDanthon, but that is essentially my backup plan. To make an algorithm that will search through counting by hand, although the one I have planned is slightly different and bigger. The thing is that the other rules I'm applying to this were all done in regular expressions too. To do this one as a regular expression would mean I used 2 lines of code instead of say 20 and would be far easier.

As I said above, it's also not written in Ruby. But Ruby and Python support regular expressions in the language, so it kinda looks like a decent place to put it.

Jay, it's not just about ensuring there are 8 a's. The regular expression needs to match the entire string which might be say 100 characters long. However every 28 consecutive characters needs to contain a minimum of 8 a's. There could be characters between each a, there could be characters after the a, there could be characters before the a. Doesn't matter as long as every 28 characters contains at least 8 a's.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Saturday, 08 December 2007, 15:23 | Permalink | Mark Here
Jayenkai


WW Entries : 103
So.. You mean.. All you need is to count the number of A's in a chunk?

Cut chunk, regex strip everything but A's, then count Len.




-----
Posted : Saturday, 08 December 2007, 16:11 | Permalink | Mark Here
JL235


WW Entries : 7
that wouldn't work. What if it was 30 a's and then 70 different characters. It would be valid up to character 50. Then the consecutive sections of 28 characters would start running out of a's. Remember this has to be consecutive.

I have also today implemented a non-regular expression version.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Saturday, 08 December 2007, 16:58 | Permalink | Mark Here
Jayenkai


WW Entries : 103
Could you give an example, because I really don't have a clue WTF you mean..!

-----
Posted : Saturday, 08 December 2007, 17:07 | Permalink | Mark Here
Dabz


WW Entries : 1
What Greenie said!!!

I'm lost too and have been trying for the last 15mins to wangle my brain round it... baring in mind... I'm drunk!!!

Which should've helped!

Dabz

-----
Mac OS X 10.6.6 (VM: WinXP3)
3.2 Ghz Intel Core (Blimey) i3
4 GB 1333 MHz DDR3
ATI Radeon HD 5670 512MB GPU
Posted : Saturday, 08 December 2007, 17:47 | Permalink | Mark Here
HoboBen


WW Entries : 9
Maybe look up Backus Naur Form - "a precise language for presenting a grammar; most grammars are written in variants of BNF."

wiki I keep meaning to write my own parser - it looks capable of nearly anything, and it's a heck of a lot simpler than RegExp!

e.g.

To define a valid variable name for a programming language, starting with a letter then using any alphanumeric letters, you could do:

-->

-----
github
Posted : Saturday, 08 December 2007, 18:07 | Permalink | Mark Here
Dabz


WW Entries : 1
Now I'm totally lost!!!

Are we looking for a simple matching selection of a certain charactor within a string, or are we defining a regular expression?

I've wrote a small interpreter in Blitzbasic:-

www.syntaxbomb.com/forum/index.php/topic,113.0.html

If thats any help... But since hobo's post (And I mean no disrespect)... I'm goosed!!!

Dabz

-----
Mac OS X 10.6.6 (VM: WinXP3)
3.2 Ghz Intel Core (Blimey) i3
4 GB 1333 MHz DDR3
ATI Radeon HD 5670 512MB GPU
Posted : Saturday, 08 December 2007, 18:18 | Permalink | Mark Here
JL235


WW Entries : 7
First, your example is a little wrong HoboBen. You should really do a lot of that in the lexical analyser picking out tokens (like words, digits, operators, brackets, braces, etc). You then put them together in the grammer. Your example seems to be trying to do both.

But I don't want to use a grammer because I'd have to connect CUP and JFlex into my project. If all that was done, then it'd be less code. But since it's not, it's a lot more and would make it more complicated.

I've now decided to use the backup option and not use the regular expression. Instead I've written a method about 20 lines long which converts it to an array of characters and looks through counting how many a's there are. When the index valud, i, becomes greater or equal to 28 I then start subtracting how many a's are at i-28. When it is in this mode there should always be 8 or more a's counted.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Saturday, 08 December 2007, 18:45 | Permalink | Mark Here
Dabz


WW Entries : 1
It seems like you have it working JL235, and my apologies for not having a clue what you said (And I still dont)....

Good luck on the project.. Whatever the hell it is! hehehe

Dabz

-----
Mac OS X 10.6.6 (VM: WinXP3)
3.2 Ghz Intel Core (Blimey) i3
4 GB 1333 MHz DDR3
ATI Radeon HD 5670 512MB GPU
Posted : Saturday, 08 December 2007, 19:52 | Permalink | Mark Here
JL235


WW Entries : 7
I can't go into it too much because it's for my assignment. I'd past the code but I'd rather now have sections strewn across the internet. However I have also just realised that although some of the rules I cannot create a regular expression that checks for a valid string, I can create one that finds an invalid string which is just as useful.

When it's complete (and if the other guys in my group agree) I will be uploading it as a showcase. So far I'm pulling my hair out over this. It's such a mess and yet only 1,600 lines.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Saturday, 08 December 2007, 20:40 | Permalink | Mark Here
power mousey




I'm dazed and confused too.
ack!! 1600 lines.

Good Luck!, JL.
Posted : Sunday, 09 December 2007, 03:24 | Permalink | Mark Here
Dabz


WW Entries : 1

1600 lines.


pffft... Its just a baby! hehehe

Dabz

-----
Mac OS X 10.6.6 (VM: WinXP3)
3.2 Ghz Intel Core (Blimey) i3
4 GB 1333 MHz DDR3
ATI Radeon HD 5670 512MB GPU
Posted : Sunday, 09 December 2007, 12:43 | Permalink | Mark Here
power mousey


um no.

to check for a valid string within a bigger string
and use 1600 lines of code.
Me thinks he should re-code or re-think the design
and algorithm to find a matching pattern and count the specific chars(bits) of the pattern with the bigger pattern or string.

hopefully, you will understand what I'm saying. I don't want nor like to write another verbose blog about it..if you don't follow me nor understand what I'm saying.
Sometimes, its a waste of my time and just not worth the common sense and obviousness of it all.
So...hopefully, you will understand.

Thats all folks.

Latest Posts
RoadRash!
spinal Sun 09:53
Noel's Graduation
spinal Sun 09:49
Screen Burn of the Mind
rockford Sun 09:01
Audio Rant
steve_ancell Sat 19:16
Wrong Partition!!!!?
spinal Sat 11:24
Progress / Location Bars
Afr0 Sat 03:15
eBay Lies
spinal Fri 23:44
Shoutbox Topic - 968
dna Fri 19:42
Development via GUI
JL235 Fri 07:59
Meh
Afr0 Fri 04:13
More

Latest Items
News : Newsletter #176
Jayenkai Sat 04:49
News : Newsletter #175
Dabz Tue 09:38
Blog : Snow: More Material Junk
Cower Sat 23:17
Dev-Diary : Mutant Monty: Amstrad CPC to Windows conversion
rockford Fri 13:14
Techy : AppleTV
Jayenkai Thu 09:40
Blog : Graphviz
steve_ancell Sat 14:17
Pets : Top-Down Shadow Hack
Jayenkai Tue 05:52
Snippet : JNKrunch v1.0
Jayenkai Sat 07:20
News : Newsletter #173
waroffice Fri 04:47
Blog : Material Loading
Cower Fri 02:08
Pets : I Done Won A Thing
shroom_monk Sun 11:31
Pets : Repurposing A Lexer
Cower Mon 22:06
Bah : Feeling a Little Angry
spinal Mon 11:26
News : Newsletter #170
Dabz Sat 00:34
Showcase : sbfgen
Cower Sat 16:57
More

Who's Online
Cower
Sun, at 10:01
spinal
Sun, at 10:00
rockford
Sun, at 09:38
Jayenkai
Sun, at 09:36
9572AD
Sun, at 08:32
CodersRule
Sun, at 08:29
Evil Roy Ferguson
Sun, at 08:13
steve_ancell
Sun, at 08:04
Afr0
Sun, at 07:52
shroom_monk
Sun, at 06:28
Link to this page
Site : Jayenkai 2006-Infinity |
MudChat's origins, BBCode's former life, Image Scaler.