Regular Expression for a string

Teja tejovathi.p at gmail.com
Thu Nov 2 06:52:30 CET 2006


John Machin wrote:

> Teja wrote:
> > HI all,
> >
> > I need to write a regular experssion for a string which satisfies the
> > following a criteria :
> >
> > 1) it should start with an alphabet
> > 2) it can contain alphabets/digits/_ from second character
> > 3) it can contain "[a-z]" or "[0-9]" at the end. but this is optional
>
> Based on the examples you give later, you don't mean "optional" (0 or 1
> occurrences), you mean 0 or more occurrences.
> Assuming "alphabet" means "English alphabetic":
>
> r"[a-zA-Z][a-zA-Z0-9_]*(\[[a-z0-9]\])*"
> 
> HTH,
> John

Thnks a lot....:)




More information about the Python-list mailing list