|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
You are getting None - nothing is printed unless you explicitly ask for a representation:
Code:
>>> a= None >>> a >>> print a None grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
|||
|
|||
|
Hey Grim,
thanks for that I got it! Code:
>>> s=identifier('360degrees')
>>> print s
None
Now I know how that goes.... Subha ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > regular expression |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|