#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    13

    regular expression


    Hi,
    This is a regex for an identifier..........

    Code:
    >>> def identifier(myId): 	
    ... 	return re.search('^[A-Za-z_]+[A-Za-z0-9_]$',myId)
    ... 
    >>> identifier('_name1')
    <_sre.SRE_Match object at 0x0117E1E0>
    >>> identifier('2name')
    >>>
    when I find a valid identifier it gives this match object....but when there is an invalid identifier I don't get anything back...according to the documentation it should return None...which I'm not getting.

    Kindly guide!!

    Thanks & Rgds,
    Subha
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    You are getting None - nothing is printed unless you explicitly ask for a representation:
    Code:
    >>> a= None
    >>> a
    >>> print a
    None
    grim
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    13
    Hey Grim,
    thanks for that I got it!

    Code:
    >>> s=identifier('360degrees')
    >>> print s
    None
    Now I know how that goes....

    Subha

IMN logo majestic logo threadwatch logo seochat tools logo