RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find PO Box
Expression
\b[P|p]?(OST|ost)?\.?\s*[O|o|0]?(ffice|FFICE)?\.?\s*[B|b][O|o|0]?[X|x]?\.?\s+[#]?(\d+)\b
Description
Modified version of Chris Myers' regexp for po boxes. This one won't match the word "box" in the address. Only matches if there is a number following the po box. Also accepts a # in front of the number and other spelling variations.
Matches
po box 123, p.o.b. #123, box 123
Non-Matches
123 box canyon rd
Author Rating: The rating for this expression. greg croasdill
Source Chris Myers plus my updates
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Updates
Name: Michael
Date: 12/20/2014 3:23:21 AM
Comment:
Greg, Thanks for your post. I've made some changes and tested them. I noticed that Postal Box was not included and also a weird case for "P.O. Box -1234" that the US Post office allows. Additionally, all the O's allow for zero other than the O in post. So I included that as well. (?i)\bp(?:[o0]st(al)?)?\.?([\-]?|\s*)?[o0]?(?:ffice)?\.?\s*b(?:[o0]x)?\.?(\s+[#\-]?(\d+))?\b Expected to NOT detect a PO box: 1234 WoodBox Road 1234 Main Street 1234 Boxwood Road 20 Post Hill 20 Box Hill Expected to detect a PO box: PO Box 1234 PO Box P.O. Box 1234 P.O. Box #1234 P.O. Box -1234 // this is legal according to USPO P.O. Box POB 65502 P.O.B. 65502 P.O.B. P.O Box PO. Box Post Office Box Post-Office Box Postal Box Postal Office Box Postal-Office Box P0stal-0ffice B0x // note the zeros P0STAL-0FFICE B0X //zeros and caps Best regards & thanks again, Michael


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials