Re: checking a string against multiple patterns

2007-12-18 Thread Jonathan Gardner
On Dec 18, 4:41 am, tomasz <[EMAIL PROTECTED]> wrote: > Is there an alternative to it? Am I missing something? Python doesn't > have special variables $1, $2 (right?) so you must assign the result > of a match to a variable, to be able to access the groups. > > I'd appreciate any hints. > Don't us

Re: checking a string against multiple patterns

2007-12-18 Thread Duncan Booth
tomasz <[EMAIL PROTECTED]> wrote: > Is there an alternative to it? Am I missing something? Python doesn't > have special variables $1, $2 (right?) so you must assign the result > of a match to a variable, to be able to access the groups. Look for repetition in your code and remove it. That will a

Re: checking a string against multiple patterns

2007-12-18 Thread Hrvoje Niksic
tomasz <[EMAIL PROTECTED]> writes: > here is a piece of pseudo-code (taken from Ruby) that illustrates the > problem I'd like to solve in Python: [...] I asked the very same question in http://groups.google.com/group/comp.lang.python/browse_frm/thread/3e8da954ff2265e/4deb5631ade8b393 It seems tha

Re: checking a string against multiple patterns

2007-12-18 Thread Tim Chase
> Define a small function with each test+action, and iterate over them > until a match is found: > > def check1(input): > match = re.search(pattern1, input) > if match: > return input[:match.end(1)] > > def check2(input): > match = re.search(pattern2, input) > if match: > return .

Re: checking a string against multiple patterns

2007-12-18 Thread grflanagan
On Dec 18, 1:41 pm, tomasz <[EMAIL PROTECTED]> wrote: > Hi, > > here is a piece of pseudo-code (taken from Ruby) that illustrates the > problem I'd like to solve in Python: > > str = 'abc' > if str =~ /(b)/ # Check if str matches a pattern > str = $` + $1# Perform some action > elsif str

Re: checking a string against multiple patterns

2007-12-18 Thread Gabriel Genellina
On 18 dic, 09:41, tomasz <[EMAIL PROTECTED]> wrote: > Hi, > > here is a piece of pseudo-code (taken from Ruby) that illustrates the > problem I'd like to solve in Python: > > str = 'abc' > if str =~ /(b)/ # Check if str matches a pattern > str = $` + $1# Perform some action > elsif str =

Re: checking a string against multiple patterns

2007-12-18 Thread kib
tomasz a écrit : > Is there an alternative to it? Am I missing something? Python doesn't > have special variables $1, $2 (right?) so you must assign the result > of a match to a variable, to be able to access the groups. > Hi Thomasz, See ie : http://www.regular-expressions.info/python.html [Se

checking a string against multiple patterns

2007-12-18 Thread tomasz
Hi, here is a piece of pseudo-code (taken from Ruby) that illustrates the problem I'd like to solve in Python: str = 'abc' if str =~ /(b)/ # Check if str matches a pattern str = $` + $1# Perform some action elsif str =~ /(a)/ # Check another pattern str = $1 + $'# Perform some oth