I want to write 3 different regular expressions. The first should detect ${ANY SEQUENCE OF CHARACTERS}
, the second should detect ${ANY SEQUENCE OF CHARACTERS=ANY SEQUENCE OF CHARACTERS}
, and the third should detect either ${ANY SEQUENCE OF NUMBERS}
or $ANY SEQUENCE OF NUMBERS
Here is what I have tried:
import sys
import os
import re
ncmd = 1
regular = re.compile('${[a-z]*}')
equals = re.compile('${*[=]*}') # string followed by equals followed by string
numbers = re.compile('${(0-9)*}|$(0-9)*') # ${ANY_SEQUENCE_OF_DIGITS} or $ANY_SEQUENCE_OF_DIGITS
while(1): #print line
line = raw_input("(%s)$ " % ncmd)
if regular.match(line):
print "Regular"
print(os.getenv(line[1:],''))
elif equals.match(line):
print "Equals"
elif numbers.match(line):
print "Numbers"
else:
print(line)
ncmd += 1