Link to home
Create AccountLog in
Avatar of catonthecouchproductions
catonthecouchproductionsFlag for United States of America

asked on

CBP regex (YYDDPP-NNNNN)

I am trying to find a regular expression for a CBP (customs border protection) - I was able to find it on a any regex lib. Any suggestions, format:

YYDDPP-NNNNN
Avatar of HonorGod
HonorGod
Flag of United States of America image

What do the letters represent?

e.g., if

  YY == A 2 digit year ? => \d{2}
  DD == A 2 digit day  ? => \d{2}
  PP  == 2 ... what? digits ? => \d{2}
  NNNNNN == A 5 digit value? \d{5}

So, maybe something like:

^\d{2}\d{2}\d{2}-\d{5}$

^ == Match beginning of line / string
$ == Match end of line / string
Assuming Y is year, D is district, P is port and N is number,

\d{6}-\d{5}

should work.

If you want only the pattern to be matched,

^\d{6}-\d{5}$

or

\b\d{6}-\d{5}\b

can be used, depending on the language you are using this RegEx in..
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of catonthecouchproductions

ASKER

Thank you all, glad you found that! I was trying to dig around to see what they meant.

@mgh_mgharish I am using Javascript with this RegEx

@ozo you say: \d{6}-\d{5} will work? Should I try this then see if I need to add the ^$ or \b?

Ryan
Is the customs assigned number the only thing in the string?
Is the string invalid if it contains anything besides the number?
Is the number part of a larger string that can contain other things?
Can the string contain other numbers?
Can the string contain other numbers with similar formats?
Can the other numbers appear adjacent to the customs number?
If the last two are both true, there may be ambiguity that could require other information to resolve.
Is the customs assigned number the only thing in the string? - YES
Is the string invalid if it contains anything besides the number? - YES, meaning anything but the CBP #
Is the number part of a larger string that can contain other things? NO
Can the string contain other numbers? Just CBP format
Can the string contain other numbers with similar formats? NO
Can the other numbers appear adjacent to the customs number? Meaning?
If the last two are both true, there may be ambiguity that could require other information to resolve.
> Is the string invalid if it contains anything besides the number? - YES,
In that case, adding the ^ and $ would be appropriate
Meaning ONLY allow the CBP format? Thanks for all your help, will try this out.