trying to match a string
arnimavidyarthy at gmail.com
Fri Jul 18 13:04:34 CEST 2008
On Jul 18, 3:46 pm, ed... at holyrood.ed.ac.uk (Eddie Corns) wrote:
> arnimavidyar... at gmail.com writes:
> >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:
> >[LRM]?L?[LRM]? etc but they do not exactly meet what I need.
> >For eg: LRLRLRLRLM is ok but LRLRLRNL is not as it has 'N' .like that.
> >The string may or may not have all the three chars.
> >>> var = 'LRLRLRNL'
> >>> residue = var.replace('L','').replace('R','').replace('M','')
> >>> if residue != '':
> ... print 'Invalid characters in input',residue
> Invalid characters in input N
That was quick.Thanks.Never thought it that angle :(
More information about the Python-list