(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.data-privacy-src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-PF5R8F7');

Knowledge Base

Alter Scan Value

What is Alter Scan?

On the Advanced step when creating/editing your services you can choose to Alter Scan Values and Alter Response Text. Please try using the examples below but if you need our help, please email support with FROM and TO examples and we’ll be happy to assist you.

This feature enables parsing the original data read when each barcode matching a specified pattern is scanned. It passes only the parsed data as the scan record, whether for recording or validation purposes. This feature is extremely useful if only a portion of the scanned data needs to be submitted, such as the data embedded in driver’s licenses, trade show badges, student and member IDs, and asset tags.

If you create a Service and want to alter a scan’s value, you need to select that option on the Advanced tab and enter scripts in the Alter Value Pattern and Alter Value Replacement fields.

How to Use ChatGPT to Generate Alter Scan Regular Expressions (Regex)

Please refer to this blog article for several examples.

  1. Inventory Audits and Cycle Counts: Remove the Leading Zero and Check-Digit from UPC Barcode
  2. Logistics: Serial Number Extraction from GS1 Code-128
  3. Medicine and Medical Equipment: Lot  Number Extraction from GS1 Code-128

Real ID Drivers License Parsing

Using Alter Scan to parse Real ID Driver Licenses, the app user can see the parsed content and the content can be exported as parsed. Alternatively, if it’s not important to show the app user the parsed data, you can instead parse when creating your Export Template. If you don’t want to show the app user the scanned data, you can customize the response fields.

Example Pattern

Pattern:

^.{Lp}(.{Lm}).{Ls}$

Replacement:

$1

The example outline is a pattern and replacement for removing a specified length prefix and suffix and keeping the specified middle.

Lp = length of prefix, Lm = length of middle, Ls = length of suffix

Extract Partial String from Full Value

Pattern:

^.{2}(.{5}).{3}$

Replacement:

$1

Pattern Breakdown

Given AB34567CDE, this pattern can change the scan value to 34567

  • ^ = Start of value.
  • .{2} = ‘AB’  –  Match any two characters.
  • (.{5}) = ‘34567’  – Match 5 characters after the first 2. The parenthesis around .{5} stores the match as a group.
  • .{3} = ‘CDE’  –  Match 3 characters after the 5 character group.
  • $ = End of value.

Replacement Breakdown

$1 = ‘34567’

The matched group of 5 characters. It’s identified as $1 because it’s the first expression inside the parenthesis. If more values were grouped then they would be identified by the order they appeared from left to right.

Second Example of Partial Value Extraction

Pattern:

^(.{2})(.{5})(.{3})$

Replacement:

$2

Here we changed the replacement to $2 because the five-character match is now the second group due to the parenthesis around each bracketed number, and we don’t want the first and third groups.

Our input of AB34567CDE is recorded as 34567.

Extraction by Character

Pattern:

^\w{3}(\w{5})$

Replacement:

$1

This substitutes an 8 numeric or alphanumeric value with just the last 5 of 8. It matches any letter, digit or underscore, equivalent to [a-zA-Z0-9_].

The replacement can take, for example, AB3456CD, and record just 456CD.

More Specific Character Extraction

Pattern:

^[a-zA-Z]{3}[a-zA-Z0-9_]*([a-zA-Z]{5})$

Replacement:

$1

If you need to get specific you can remove any of the character types a-z or A-Z or 0-9 or _. Here, we only accept upper or lower case letters and not numbers or underscores. We have defined that there are 3 letters to exclude and then an unknown number of characters of any kind before we get to the group of 5 letters we want.

Our input of ABC123Fruit becomes just “Fruit”

Extracting Every Other Character

Pattern:

(\w)\w

Replacement:

$1

Should you need every other character recorded from a string, you can use the above pattern.

An input of “OArpapnlgee” becomes just “Orange”

Extracting Strings

Extracting the First String of Characters

Pattern:

^([\s\S]{100})([\s\S]*)$

Replacement:

$1

Here the result will be the first 100 characters of the scanned value. You can change {100} to the number of characters you wish to include.

Extracting a Mid-Section String of Characters

Pattern:

(MID,START,LENGTH) translates to regex ^[\w{START_MINUS_ONE}([\w]{LENGTH})[\w]*$

Replacement:

$1

Examples:

Regex  ->  Sample String (ignore [ ] )  ->  Result

^[\w]{3}([\w]{7})[\w]*$  ->  123[4567890]xyz  ->  4567890
^[\w]{2}([\w]{10})[\w]*$  ->  12[34567890xy]z  ->  34567890xy

URL Replacement

Pattern:

http:\/\/example\.com\/([\s\S]*)\\\?token=([\s\S]{14})$

Replacement:

http://example.com/TO_THIS.php?token=$2

This pattern replaces part of a URL. The scanned URL http://example.com/FROM_THIS\?token=11111111111111 will become http://example.com/TO_THIS\?token=11111111111111. That is because this regex replaces ‘FROM_THIS’ with ‘TO_THIS’ and all else remains the same. Notice that escaping (\) is required within the URL.

Adding a Prefix

Pattern:

([^a-zA-Z][\s\S]*)$

Replacement:

x$1

(where ‘x’ is the prefix to add)

For this example, we want to add a prefix to a barcode value, but only if there’s no alpha character prefix.

The replacement changes 1234567890 to A1234567890 in the scan record.

Extracting Partial Value from a URL

Pattern:

http:\/\/example\.com\/assets\/(([\s\S]*).{1,}).html

Replacement:

$1

Here the scanned barcode value ‘http://example.com/assets/A42V9.html’ would then be altered to show just the value A42V9. Notice that escaping (\) is required within the URL.

Note: If you parse out just the value but want the URL to be clickable in the response text, use the following for the Alter Response Value fields.

Alter pattern: ^[\s\S]*$
Alter response: $0 http://www.base_URL_here $(SCAN_VALUE)

Removing a Prefix

Known Prefix

Pattern:

^(\(00\)|\(J\))([\S\s]*?)$

Replacement:

$2

In this example, the regex will remove the prefix ‘(00)’ or ‘(J)’ from the scanned barcode and keep any characters after those.

Note: The ‘\’ escape before each of the parentheses is needed within the ( ) structure.

Unknown Prefix

Pattern:

^([\s\S]*?)\$([\s\S]*?)

Replacement:

$2

This regex will remove all data before a ‘$’ symbol in the barcode and only keep numbers or characters after it. It won’t include the ‘$’ in the result, either.

Note: The ‘\’ escape before the ‘$’ symbol is necessary because ‘$’ is a special type of coding character.

Removing Characters in a Placement

Pattern:

^[\s\S]{1}([\s\S]*)$

Replacement:

$1

Here the regex will remove the first character of the scanned barcode.

Specific Character Removal

Pattern:

^[\s\S]{3}([\s\S]*)[\s\S]{3}$

Replacement:

$1

If you want to specifically target a number or letter you would substitute [\s\S] with the characters you want to remove. Here we target ABC and 123 so that our output is only “Fruit” when given an input of ABCFruit123. This regex will remove the first and last group of 3 characters and return only what is left of the string.

Replacing Matching Characters

Pattern:

^[C]{1}([\s\S]*)$

Replacement:

B$1

This regex will remove the first character of the scanned barcode if it’s a capital ‘C’ but the replacement will replace the ‘C’ with a ‘B’.

Parsing a URL with Extra Characters

Pattern:

^[\s\S]*?ticket_id=([\s\S]*)&[\s\S]*?$

Replacement:

$1

In this example, the ticket/coupon/voucher/asset barcode is a variable within a URL like this:

https://www.your_web_url?event_qr_code=1&ticket_id=10148&event_id=5083

The above regex will parse the string after “ticket_id=

Assumes: [anything]ticket_id=[what_you_want_to_capture][anything]

Assumes: there is an ‘&’ after [what_you_want_to_capture]

Removing Special Characters

Pattern:

^([\s\S]*?)\|([\s\S]*)$

Replacement:

$1

Here the regex will remove the “|” and all the characters after that. For example “12345|text|text” will become just “12345”.

Adding a Separator

Pattern:

^([\s\S]{10})([\s\S]*?)([\s\S]{20})$

Replacement:

$1-$3

The result of this replacement will be the first 10 characters and the last 20 characters of the barcode value with a “-” separator added between each group. You can change the “-” to another separator if needed. For example, if you prefer the “+” symbol the replacement would be “$1+$3”.

Removing a Suffix

Known Suffix

Pattern:

^([\s\S]*)(abc|ABC)$

Replacement:

$1

This will remove the known suffix “abc” or “ABC”.

Unknown Suffix

Pattern:

^([\s\S]*)([\d]{1})$

Replacement:

$1

Using {1} will remove an unknown suffix of one digit. Using {2} will remove an unknown suffix of two digits. Using [\d] removes only digits. Using [\s\S] will remove all alpha characters and digits.

Removing a Space

Pattern:

^([\s\S]*?)[\s]([\s\S]*?)

Replacement:

$1$2

This will remove the “space” between two strings. For example, the value “12345 abcde” will become “12345abcde”.