python po box split for auth.net
The regular expression '(P[\.\s]*O[\.\s]*Box)?\s*(\d+)\s*(P[\.\s]*O[\.\s]*Box)?' will match almost anything that looks like a PO Box (but will match a number only address too). The replacement '\2 PO Box' would normalize the data.
So the code would be something like this

import re
rgx = re.compile(r'(P[\.\s]*O[\.\s]*Box)?\s*(\d+)\s*(P[\.\s]*O[\.\s]*Box)?')
addrs = ('PO Box 001', 'P.O. Box 002', 'P.O.Box 003', '004 P.O. Box', '005 PO Box', '006')
for addr in addrs:
    print rgx.sub(r'\2 PO Box', addr)
Authorize.net ( or the banks ) will not validate an address unless for a PO Box address, unless its in the form of 123 P.O. Box. Most people use P.O Box 123. There are loads of variations PO Box formats and I need an algorithm that puts the number in front of the PO Box
Any suggests would be helpful.