[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

regex



This is not an openbsd problem but maybe someone can help anyway...I've got a
string in the form [NSEW]+ It is a series of directions that are repeatedly
followed until a goal is reached thus EEESEEES is essentially the same as EEES
and EEE is essentially the same as E. I'm writeing a function (in python) to
reduce these strings to simplest form as above. I'm trying to use python's
regex matching functions(the same as perl regex's)to do this.
My first thought was to do the following where s is the string, sl is the len
of s, and x is the set of divisors of sl.

y = sl / x
m = re.match("([NSEW]{%i}){%i}" % (x,y),s)

the problem is, the regex(using x is 2 and y is 4 for example) ([NSEW]{2}){4}
evaluates the same as [NSEW]{8} which will match any a character string and
this is obviously not the desired result. Is there a way to pre-evaluate a
regex group? Any other suggestions on how to do this or am I gonna have to do
it the long way?
------------------
Trevor R.H. Clarke                     Computer Science House
Rochester Institute of Technology      Systems Programmer for ISC
retrev@csh.rit.edu                     trcsys@rit.edu
http://www.csh.rit.edu/~retrev/        finger retrev@csh.rit.edu for PGP key