Barcode Regexes
The barcode regex is a regular expression that will be used to parse scanned product barcodes into the material code, serial number, batch number, and expiration date fields when adding items. This increases the speed and accuracy of adding new items compared to manually typing in each of these fields.
If you don't have access to a technical resource to help build your regular expressions, there are many online tools for aiding anyone in building and testing a regex to parse your product's barcode format. We recommend regexstorm.net which provides a quick reference of the characters used, as well as a tool for testing your regex by entering real (or simulated) barcodes and seeing how the regex you have built "reads" the barcode. Stratosphere uses the .NET regex engine, which will match this tool exactly.
Let’s walk through a straightforward example of building a regex pattern to read a GS1-compliant barcoded product:
Visible Barcode: (01)00123655093160(10)12345678(17)210831(21)12373438003(30)1
Barcode Output when scanned into Barcode field: ]C101001236550931601012345678172108312112373438003301
This barcode format contains four separate fields we want to parse.
GS1 Code | Field | Value |
---|---|---|
01 | itemnumber | 00123655093160 |
10 | batch | 12345678 |
17 | expirationdate | 210831 |
21 | serialnumber | 12373438003 |
The final field, quantity, is not currently a field in Stratosphere, but your regex will need to account for additional non-parsed fields like this too. Only barcode regexes that match every character in a scanned barcode will be able to parse your barcode, so be sure to account for every character in the barcode, being as specific as possible, but allowing for a range of possible values where needed. An example of a barcode regex that would match our example barcode output is:
^(?:\]C1)?(?:01(?'itemnumber'\d{14}))?(?:10(?'batch'\d{8}))?(?:17(?'expirationdate'\d{6}))?(?:21(?'serialnumber'\d{11}))?...$
Let's break that down into its parts:
Regex | Description |
---|---|
^ | Defines that the regex must start matching from the beginning of the input barcode. Without this, the regex could begin matching in the middle of the regex, increasing the risk of incorrect match. |
(?:\]C1) | Instructs the regex to look for a subpattern that is literally the characters ]C1. These three characters are included in the example barcode scan as a prefix, though they do not contain product information. |
? | Allows for the absence of the preceding pattern, in this case "]C1" |
(?:01 | Matches a literal "01", which is the GS1 identifier that the following digits represent the item number (aka GTIN) |
(?'itemnumber'\d{14})) | (?'itemnumber' ) - gives a name to the regex \d{14}. \d means any digit (0-9) and the {14} indicates 14 consecutive characters. Altogether, this means that if there are 14 consecutive numbers at this place in the barcode, it should be read by Stratosphere as the itemnumber and used to fill the product field. |
? | Allows for the absence of the preceding pattern, in this case "0100123655093160" |
(?:10 | Matches a literal "10", which is the GS1 identifier that the following digits represent batch. |
(?'batch'\d{8})) | (?'batch' ) - gives a name to the regex \d{8}. \d means any digit (0-9) and the {8} indicates 8 consecutive characters. Altogether, this means that if there are 8 consecutive numbers at this place in the barcode, it should be read by Stratosphere as the batch and used to fill the batch field. |
? | Allows for the absence of the preceding pattern, in this case "1012345678". |
(?:17 | Matches a literal "17", which is the GS1 identifier that the following digits represent expiration date. |
(?'expirationdate'\d{6})) | (?'expirationdate' ) - gives a name to the regex \d{6}. \d means any digit (0-9) and the {8} indicates 6 consecutive characters. Altogether, this means that if there are 6 consecutive numbers at this place in the barcode, it should be read by Stratosphere as the expiration date and used to fill the expiration date field. |
? | Allows for the absence of the preceding pattern, in this case "17210831". |
(?:21 | Matches a literal "21", which is the GS1 identifier that the following digits represent serial number. |
(?'serialnumber'\d{11})) | (?'serialnumber' ) - gives a name to the regex \d{11}. \d means any digit (0-9) and the {11} indicates 11 consecutive characters. Altogether, this means that if there are 11 consecutive numbers at this place in the barcode, it should be read by Stratosphere as the serial number and used to fill the serial number field. |
? | Allows for the absence of the preceding pattern, in this case "2112373438003". |
... | Any single characters. These three characters are included in the barcode scan (quantity), but are not used. |
$ | Defines that there should be no more characters at this point. Without this, the regex could match on a barcode that contains additional characters, increasing the risk of an incorrect match. |
In our case, the Expiration Date Format should be yyMMdd to interpret 210831 as August 31st, 2021. If the barcode includes slashes or dashes between parts of the date, include this in your date formation. For example, if the scanned barcode read 21/08/31, then you should account for the / characters in your regex and include slashes in the Expiration Date Format field: yy/MM/dd.
It is possible to make the regex example above even more specific. For example, by requiring the 3rd number in the expiration date (210831) to always be either a 0 or a 1, you could greatly increase the chance that this character really is the first number in the month. Making your barcode regexes as specific as possible is important if you are reading a wide variety or product barcode formats, and do not want these barcodes being interpreted by multiple barcode regexes. Stratosphere permits the addition of an unlimited number of barcode regexes to compare against, but multiple regexes should only be used if each one is sufficiently specific to avoid duplicate matches.
Alternatively, the Regex could be made quite loose to handle a wider variety of barcodes, by allowing multiple lengths for each group, permitting a broader range of characters, or by removing the ^ and $ beginning and ending anchors.
Without a barcode regex that matches the scanned barcode, no information can be parsed into the item fields when adding a new item. The product barcode becomes effectively a worthless string of numbers, and the batch, serial, product, and expiration date information must be manually entered, which takes about 20-30 seconds per item.
With a barcode regex that matches the scanned barcode, information can be automatically parsed from the barcode into the item fields when adding a new item. This turns adding an item into a matter of two quick barcode scans, and pressing "Save Changes," which takes about 3-4 seconds per item.
Viewing barcode regexes requires the "Product Management" role to be granted in your user record. Contact your system administrator to add this capability.
Barcode regexes are viewed and managed inside the Product Catalog page, via the "Manage Barcode Regexes" button.
To view a barcode regex's details, click the name of the barcode regex. In the details page you will see all the available information for that barcode regex, including:
- Name - An easily recognizable description of the Barcode Regex.
- Regex* - The Regular Expression used to parse the barcode into discrete data in Stratosphere. See example at the beginning of this article.
- Expiration Date Formation - Needed if the regex parses expiration date. The regex can determine which numbers indicate the expiration date, but not what those numbers mean. Each number specified by the regex to be part of the expiration date must be interpreted as being part of the day, month, or year.
- d stands for Day
- m stands for Month
- y stands for Year
* = Required
Adding barcode regexes requires the "Product Management" role to be granted in your user record. Contact your system administrator to add this capability.
Barcode Regexes are added to Stratosphere in order to aid in the rapid addition of items, which can use any matching barcode regex to parse the item’s barcode for any useful data to automatically associate with the item.
You should make each Regex you add as specific as possible to reduce the chance that the barcode regex will "match" on barcodes it is not intended to read. For example, if you know the 1st character of a particular barcode will always be 0, specify 0 rather than just allowing any character, or even any number. When a user is adding items and the barcode they scan matches multiple barcode regexes, they will be forced to choose which of the matching regexes they want to use. If a barcode matching multiple barcode regexes is a frequent occurrence, this will significantly slow down the addition of items.
If you are tracking product from multiple manufacturers, you will likely need to add (at least) one new Barcode Regex for every manufacturer. Even if they all follow GS1 or some other standard, the order, use of numbers vs letters, and length of various fields will likely differ. Making one regex work across many different manufacturers in these circumstances would result in a dangerously loose Regex that risks misinterpreting barcodes.
To add a barcode regex,
- Select "Add Barcode Regex" in the top left of the barcode regex page.
- Enter a Name, if desired.
- Enter a Regex.
- Enter an Expiration Date Formation, if the Regex is parsing expiration dates.
- Click Save Changes to finish adding the Barcode Regex. The Barcode Regex will appear in the Barcode Regexes table.
Editing Barcode Regexes requires the "Product Management" role to be granted in your user record. Contact your system administrator to add this capability.
There are two options for editing a Barcode Regex.
- On the Barcode Regex page, open the quick action menu for the barcode regex you wish to edit and select "Edit."
- In the Edit Barcode Regex window that opens, make any desired changes.
- Click "Save Changes" to save the edited record. Clicking "Cancel" or the X in the top right of the window will remove any edits you just made but had not yet saved.
- On the Barcode Regex page, click the barcode regex name link.
- In the Barcode Regex details page, make any desired changes.
- Click "Save Changes" to save the edited record. To cancel your edits, close or leave the barcode regex details page without saving.
Deleting Barcode Regexes requires the "Product Management" role to be granted in your user record. Contact your system administrator to add this capability.
Deleting a Barcode Regex prevents items added in the future from using that Barcode Regex to parse an item's barcode. It will not affect any existing items that may have utilized the Barcode Regex when they were added.
- On the Barcode Regex page, open the quick action menu for the barcode regex you wish to delete and select "Delete."
- In the "Delete Barcode Regex" confirmation window that appears, click "Delete" to confirm the deletion of the barcode regex. Clicking "Cancel" or the X in the top right of the window will not delete the Barcode Regex.
- On the Barcode Regex page, click the barcode regex name of the Barcode Regex you wish to delete.
- On the Barcode Regex Details page that opens, scroll to the bottom of the page and click "Delete".
- In the "Delete Barcode Regex" confirmation window that appears, click "Delete" to confirm the deletion of the Barcode Regex. Clicking "Cancel" or the X in the top right of the window will not delete the Barcode Regex.
Q. What Regex Pattern Syntax does Stratosphere use?
A. Stratosphere uses Microsoft's .NET Regular Expression Engine, which is based on the PERL 5 standard. See https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference for more information, or use regexstorm.net as a reference.
Q. Can I name groups in my Regex beyond the fields that Stratosphere will use? Manufacturing Date, for example?
A. As long as the Regex matches the barcode, Stratosphere will fill in the fields it recognizes, while ignoring additional fields. It will not cause an error or prevent the Regex from matching.
Q. I have products with multiple barcodes, can I still use Regexes when adding items?
A. Yes, users adding items can scan in multiple barcodes to the barcode field (one at a time), and have each of them be parsed without clearing already parsed fields, as long as each barcode has a valid Regex and their information does not conflict.