I've been dabbling in a bit of python. A good friend of mine, Michael, has given me a head start on this (http://benz.io/posts/Python-Regex/) - the re
module is very nifty.
re.match
can return a "None" or matched result using Michael's example, so we can perform boolean checks on the data
import re
a = re.compile("^.*[0-9]")
result = a.match("Michael")
if result != None:
print "Match!"
else:
print "No Match :("
If however you want to print all matches (equivalent to something like grep {regex-statement}
) you can use re.findall
to achieve this
import re
def get_NY_cobbler_hosts():
hosts = subprocess.check_output(['cobbler', 'system', 'list'])
### Assuming all new-york hostnames begin with "ny"
hostlist = list(re.findall('ny.*', hosts))
return hostlist