regular expression back references
John Machin
sjmachin at lexicon.net
Sat Aug 9 00:23:13 EDT 2003
On Fri, 8 Aug 2003 20:40:27 -0600, "Andrew Dalke"
<adalke at mindspring.com> wrote:
>Clay Shirky
>> # use regexes to see what to split on
>> if re.search(":", new_address):
>
>or use
> if ":" in new_address:
>
>> elif re.search("-", new_address):
>> new_list = new_address.split("-")
>> elif re.search(".", new_address):
>> new_list = new_address.split(".")
>
>and include a
> else:
> raise Exception("I have no idea what you're asking for")
>
>and maybe some ValueError catching in the int call.
>
instead maybe something like
new_list = []
for sep in '-.:':
if sep in new_address:
new_list = new_address.split(sep)
break
if len(new_list) != 6:
raise .......
plus also a test that each octet is in range(256) ....
More information about the Python-list
mailing list