Page 1 of 1

Regex help.

Posted: Sat Dec 20, 2003 2:56 pm
by penguinboy
Well, I have a pattern, and it works.
But... I have a feeling there has to be a shorter/better way to write this.

Code: Select all

(
(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])
ї,]
(їA-f0-9])(їA-f0-9])
ї,]
)
some example

1c,cd,90,80a04040,00000377,0000039d,003b,00,01,02,00,
01,01,01,01234567,01234567,01234567,0123,01,01,01,01,
ab,ab,ab,abcdefAB,abcdefAB,abcdefAB,abcd,ab,ab,ab,ab,

Basically the pattern matches
a-f upper or lowercase and 0-9.
x2,x2,x2,x8,x8,x8,x4,x2,x2,x2,x2,


This patteren works and I'm not concerned about execution time,
because I only run this once in the script,
but I would like to understand regex syntax a little more.

I know(hope :) ) there is at least a shorter way to do this....

Anyway.. thanks for any help.

--pb

Posted: Sat Dec 20, 2003 3:05 pm
by Derfel Cadarn
Well, I'm no regex-expert myself, but I know there is this option a{4} which looks for exactly four a's. So, I think you could shorten

Code: Select all

(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])(їA-f0-9])
into

Code: Select all

їA-f0-9]{8}
and so on...

===================================
= Yes, I'm trying to get my 101st posting today =
===================================

Posted: Sat Dec 20, 2003 3:19 pm
by penguinboy
Wow thats awsome thanks alot!

I shortened it to:

Code: Select all

(
їA-f0-9]{2}ї,]
їA-f0-9]{2}ї,]
їA-f0-9]{2}ї,]
їA-f0-9]{8}ї,]
їA-f0-9]{8}ї,]
їA-f0-9]{8}ї,]
їA-f0-9]{4}ї,]
їA-f0-9]{2}ї,]
їA-f0-9]{2}ї,]
їA-f0-9]{2}ї,]
їA-f0-9]{2}ї,]
)