RegEx Examples: ICCID, IMEA, and ABN without mod-89 check
An Australian Business Number (ABN) is a unique 11-digit identifier used to identify businesses to the government, suppliers, and the public. It consists of a 9-digit identifier plus 2 leading check digits. The "mod-89 check" is an algorithm that verifies that the two leading digits are correctly derived from the following nine digits. This validates if an ABN is correctly structured, helping to identify common data entry errors like digit transposition.
Regex (using the pipe '|' character as an OR between conditions):
pData->data =
_T("(?i)"
"(?:"
"\\bICCID\\b[^\\r\\n]*?(?<!\\d)89\\d{17,18}(?!\\d)"
"|(?<!\\d)89\\d{17,18}(?!\\d)[^\\r\\n]*?\\bICCID\\b"
"|\\b(?:IMEA|IMEI|SIM)\\b[^\\r\\n]*?(?<!\\d)\\d{15}(?:\\d{2})?(?!\\d)"
"|(?<!\\d)\\d{15}(?:\\d{2})?(?!\\d)[^\\r\\n]*?\\b(?:IMEA|IMEI|SIM)\\b"
"|\\bABN\\b[^\\r\\n]*?(?<!\\d)[1-9]\\d\\s?\\d{3}\\s?\\d{3}\\s?\\d{3}(?!\\d)"
"|(?<!\\d)[1-9]\\d\\s?\\d{3}\\s?\\d{3}\\s?\\d{3}(?!\\d)[^\\r\\n]*?\\bABN\\b"
")");
In simple terms:
(?i)– Make everything case-insensitive.- The terms
abn,ABN,Imei, etc. all match
- The terms
- The big
(?: ... )group is just a list of OR conditions.
It’s looking for three types of IDs, each tied to the right label on the same line: - ICCID
- Looks for the word
ICCIDand a number that: - Starts with
89 - Has 17 or 18 more digits after that (so 19–20 digits total).
- Starts with
ICCIDcan be before or after the number.- It allows any characters between them on that line (spaces, punctuation, etc.).
- It makes sure the number is not part of a longer digit string.
- Looks for the word
- IMEA / IMEI / SIM
- Looks for one of the labels
IMEA,IMEI, orSIMand a number that is: - 15 digits, optionally followed by 2 more digits (so 15 or 17 digits total).
- Again, the label can be before or after the number on the same line.
- Ensures the number isn’t embedded inside a bigger run of digits.
- Looks for one of the labels
- ABN (Australian Business Number)
- Looks for the word
ABNand an 11-digit number that: - Starts with a digit from 1–9 (no leading 0).
- May be formatted with optional spaces like
53 004 085 617.
ABNcan be before or after the number on the same line.- Also makes sure the ABN number isn’t part of a longer digit string.
- Looks for the word
[^\r\n]*?– “Any characters on the same line” between the label and the number.(?<!\d)/(?!\d)– “The thing we matched isn’t glued to extra digits on either side.”