Re: trying to match a string

2008-07-21 Thread oj
On Jul 21, 11:04 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > The drawback is that it's a lot easier to mess up the edge cases if you > do that (as this thread has shown).  The small speedup you get in > typical cases is quickly offset by extra debugging/testing time (or, for > that matter, argui

Re: trying to match a string

2008-07-21 Thread Fredrik Lundh
oj wrote: Fine, this works, although match instead of search blah blah blah as has already been mentioned. I still think searching for one invalid character is more elegant then trying to match the entire string, but that's just personal preference, I guess. The drawback is that it's a lot eas

Re: trying to match a string

2008-07-21 Thread oj
On Jul 19, 3:04 am, Andrew Freeman <[EMAIL PROTECTED]> wrote: > let me revise it please: > > To show if valid: > > if re.search(r'^[LRM]*$', 'LM'): >     print 'Valid' Fine, this works, although match instead of search blah blah blah as has already been mentioned. I still think searching for one i

Re: trying to match a string

2008-07-20 Thread Andrew Freeman
John Machin wrote: On Jul 20, 11:14 am, Andrew Freeman <[EMAIL PROTECTED]> wrote: John Machin wrote: (4) I highly doubt that this code was actually to be used in an interactive session, The offending code is a nonsense wherever it is used. the False/True output was trun

Re: trying to match a string

2008-07-19 Thread John Machin
On Jul 20, 11:14 am, Andrew Freeman <[EMAIL PROTECTED]> wrote: > John Machin wrote: > (4) I highly doubt that this code was actually to be used in an > interactive session, The offending code is a nonsense wherever it is used. > the False/True output was truncated intentionally, What meaning ar

Re: trying to match a string

2008-07-19 Thread Andrew Freeman
John Machin wrote: On Jul 20, 5:00 am, Andrew Freeman <[EMAIL PROTECTED]> wrote: Andrew Freeman wrote: John Machin wrote: A couple of points: (1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...) (2) You need to choose your end-anchor correctly; your pattern is pe

Re: trying to match a string

2008-07-19 Thread John Machin
On Jul 20, 5:00 am, Andrew Freeman <[EMAIL PROTECTED]> wrote: > Andrew Freeman wrote: > > John Machin wrote: > >> A couple of points: > >> (1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...) > >> (2) You need to choose your end-anchor correctly; your pattern is > >> permitting a ne

Re: trying to match a string

2008-07-19 Thread Andrew Freeman
Andrew Freeman wrote: John Machin wrote: A couple of points: (1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...) (2) You need to choose your end-anchor correctly; your pattern is permitting a newline at the end: I forgot to change search to match. This should be better: def ma

Re: trying to match a string

2008-07-19 Thread Andrew Freeman
John Machin wrote: On Jul 19, 12:04 pm, Andrew Freeman <[EMAIL PROTECTED]> wrote: To show if valid: if re.search(r'^[LRM]*$', 'LM'): print 'Valid' A couple of points: (1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...) (2) You need to choose your end-anchor corre

Re: trying to match a string

2008-07-18 Thread John Machin
On Jul 19, 12:04 pm, Andrew Freeman <[EMAIL PROTECTED]> wrote: > To show if valid: > > if re.search(r'^[LRM]*$', 'LM'): > print 'Valid' > A couple of points: (1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...) (2) You need to choose your end-anchor correctly; your pattern is p

Re: trying to match a string

2008-07-18 Thread Andrew Freeman
oj wrote: Why not just use * instead of + like: if re.search(r'^[^LRM]*$', var): # note: ^ outside [] is start of string; $ means end of string print "Invalid" This will *only* print invalid when there is a character other than L, R, or M or a empty string. Sorry, forge

Re: trying to match a string

2008-07-18 Thread oj
> > > Why not just use * instead of + like: > > > if re.search(r'^[^LRM]*$', var): # note: ^ outside [] is start of > > string; $ means end of string > >    print "Invalid" > > > This will *only* print invalid when there is a character other than L, > > R, or M or a empty string. > > Sorry, forget

Re: trying to match a string

2008-07-18 Thread John S
On Jul 18, 7:51 am, Andrew Freeman <[EMAIL PROTECTED]> wrote: > Andrew Freeman wrote: > > oj wrote: > >> On Jul 18, 12:10 pm, John Machin <[EMAIL PROTECTED]> wrote: > > >>> On Jul 18, 9:05 pm, oj <[EMAIL PROTECTED]> wrote: > > On Jul 18, 11:33 am, [EMAIL PROTECTED] wrote: > > > Hi, > >

Re: trying to match a string

2008-07-18 Thread arni
On Jul 18, 7:51 pm, Andrew Freeman <[EMAIL PROTECTED]> wrote: > Andrew Freeman wrote: > > oj wrote: > >> On Jul 18, 12:10 pm, John Machin <[EMAIL PROTECTED]> wrote: > > >>> On Jul 18, 9:05 pm, oj <[EMAIL PROTECTED]> wrote: > > On Jul 18, 11:33 am, [EMAIL PROTECTED] wrote: > > > Hi, > >

Re: trying to match a string

2008-07-18 Thread Andrew Freeman
Andrew Freeman wrote: oj wrote: On Jul 18, 12:10 pm, John Machin <[EMAIL PROTECTED]> wrote: On Jul 18, 9:05 pm, oj <[EMAIL PROTECTED]> wrote: On Jul 18, 11:33 am, [EMAIL PROTECTED] wrote: Hi, Hi, I am taking a string as an input from the user and it should only

Re: trying to match a string

2008-07-18 Thread Andrew Freeman
oj wrote: On Jul 18, 12:10 pm, John Machin <[EMAIL PROTECTED]> wrote: On Jul 18, 9:05 pm, oj <[EMAIL PROTECTED]> wrote: On Jul 18, 11:33 am, [EMAIL PROTECTED] wrote: Hi, Hi, I am taking a string as an input from the user and it should only contain the chars

Re: trying to match a string

2008-07-18 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: I am taking a string as an input from the user and it should only contain the chars:L , M or R How about skipping re's and doing something like: set(input_string) <= set('LMR') If you want to disallow the empty string: set([]) < set(input_string) <= set('LMR') --S

Re: trying to match a string

2008-07-18 Thread oj
On Jul 18, 12:10 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Jul 18, 9:05 pm, oj <[EMAIL PROTECTED]> wrote: > > > > > On Jul 18, 11:33 am, [EMAIL PROTECTED] wrote: > > > > Hi, > > > > Hi, > > > > I am taking a string as an input from the user and it should only > > > contain the chars:L , M or

Re: trying to match a string

2008-07-18 Thread John Machin
On Jul 18, 9:05 pm, oj <[EMAIL PROTECTED]> wrote: > On Jul 18, 11:33 am, [EMAIL PROTECTED] wrote: > > > > > Hi, > > > Hi, > > > I am taking a string as an input from the user and it should only > > contain the chars:L , M or R > > > I tried the folllowing in kodos but they are still not perfect: >

Re: trying to match a string

2008-07-18 Thread oj
On Jul 18, 11:33 am, [EMAIL PROTECTED] wrote: > Hi, > > Hi, > > I am taking a string as an input from the user and it should only > contain the chars:L , M or R > > I tried the folllowing in kodos but they are still not perfect: > > [^A-K,^N-Q,^S-Z,^0-9] > [L][M][R] > [LRM]?L?[LRM]? etc but they do

Re: trying to match a string

2008-07-18 Thread arni
On Jul 18, 3:46 pm, [EMAIL PROTECTED] (Eddie Corns) wrote: > [EMAIL PROTECTED] writes: > >Hi, > >Hi, > >I am taking a string as an input from the user and it should only > >contain the chars:L , M or R > >I tried the folllowing in kodos but they are still not perfect: > >[^A-K,^N-Q,^S-Z,^0-9] > >[L

Re: trying to match a string

2008-07-18 Thread John Machin
On Jul 18, 8:33 pm, [EMAIL PROTECTED] wrote: > Hi, > > Hi, > > I am taking a string as an input from the user and it should only > contain the chars:L , M or R > > I tried the folllowing in kodos but they are still not perfect: > > [^A-K,^N-Q,^S-Z,^0-9] > [L][M][R] > [LRM]?L?[LRM]? etc but they do

Re: trying to match a string

2008-07-18 Thread Eddie Corns
[EMAIL PROTECTED] writes: >Hi, >Hi, >I am taking a string as an input from the user and it should only >contain the chars:L , M or R >I tried the folllowing in kodos but they are still not perfect: >[^A-K,^N-Q,^S-Z,^0-9] >[L][M][R] >[LRM]?L?[LRM]? etc but they do not exactly meet what I need.

trying to match a string

2008-07-18 Thread arnimavidyarthy
Hi, Hi, I am taking a string as an input from the user and it should only contain the chars:L , M or R I tried the folllowing in kodos but they are still not perfect: [^A-K,^N-Q,^S-Z,^0-9] [L][M][R] [LRM]?L?[LRM]? etc but they do not exactly meet what I need. For eg: LRLRLRLRLM is ok but LRLRL

trying to match a string

2008-07-18 Thread arnimavidyarthy
Hi, Hi, I am taking a string as an input from the user and it should only contain the chars:L , M or R I tried the folllowing in kodos but they are still not perfect: [^A-K,^N-Q,^S-Z,^0-9] [L][M][R] [LRM]?L?[LRM]? etc but they do not exactly meet what I need. For eg: LRLRLRLRLM is ok but LRLRL