I'm trying to write a regex to detect any c/o patterns in my address line.
I want my regex to detect patterns like Care Of, c/o, c.o., CareOf, etc.
I've done PO Box, email address validations, etc. in the past, but this is new to me.
I'm not very strong in this area and am still trying at my end, but any help would be greatly appreciated.
Thanks much.
Adding further detail to my question:
-> I'm attempting this in Java (through a server side call) and Javascript (through a client side call).
-> I'm doing this for address validation; we want to make sure that the customer doesn't add Care Of addresses (similar to PO Box validation)
I need to parse through Address Line 1 and Address Line 2 (text boxes) values in my page and show an error message if any of them contains a 'Care Of' value.
Possible inputs: 'Care Of John', 'c/o John', 'C/O John', 'C.O. John'
Required output: If there is a pattern match, I need to show an error message: 'Sorry, we do not ship to C/O addresses'.
-
2Would you mind adding expected input and output?Benjamin Gruenbaum– Benjamin Gruenbaum2013年10月21日 22:22:40 +00:00Commented Oct 21, 2013 at 22:22
-
Are you trying to use regex to parse a street address? This gets messy. Fast. Consider sending SmartyStreets an email (I work at SmartyStreets) for help on this from the professionals. ;)Matt– Matt2013年10月21日 22:43:17 +00:00Commented Oct 21, 2013 at 22:43
-
@BenjaminGruenbaum: Sorry I missed that. I've added further details.theAspirant– theAspirant2013年10月22日 17:55:00 +00:00Commented Oct 22, 2013 at 17:55
-
@Matt: I'm gonna take a deeper look at your site, but I don't believe my team has budget for additional custom APIs. :)theAspirant– theAspirant2013年10月22日 17:55:35 +00:00Commented Oct 22, 2013 at 17:55
-
@theAspirant Doesn't matter -- just ask them your question (which isn't well-suited for Stack Overflow as-is, hence the close votes) and they'll answer via email. And anyway, the API is free for low-volume or non-profit use.Matt– Matt2013年10月22日 17:57:40 +00:00Commented Oct 22, 2013 at 17:57
2 Answers 2
This matches all of your given inputs:
(?i)c(are|.|/) ?o(\.|f)?
1 Comment
You should probably just have a single expression with a series of alternations in it:
"Care Of|C\/O|C\.O\.|CareOf"
And set it to case-insensitive.
What language are you working in?
2 Comments
Care *Of