Python re module's stuff # 1
When you do something with aws, then you need only ip-address from something like this
$ ec2-1-2-3-4.ap-southeast-1.compute.amazonaws.com
$ ec2-1-2-3-4.ap-southeast-1.compute.amazonaws.com
I used to deal with it like split something then concat with something. Now I just found something cool in python's re module.
>>> import re
>>> ec2_ip = re.search(r'ec2-(\d+)-(\d+)-(\d+)-(\d+), ).groups()
so I get
>>> print ec2_ip
'1.2.3.4'
yaha, love this.
Comments
Post a Comment