Knowledge Base

View Categories

Alter Scan Value

How to Use the Alter Scan Feature for Enhanced Barcode Parsing

The Alter Scan feature allows you to modify scanned barcode values by parsing specific data segments and formatting them for validation or export. This tool is particularly useful for extracting relevant data from barcodes used in driver’s licenses, trade show badges, student IDs, and asset tags.

By following the steps outlined below, you can customize how scanned values are processed to meet your specific needs.

What is Alter Scan?

The Alter Scan feature enables the transformation of barcode scan data by:

  1. Parsing the original scanned value to extract specific data.
  2. Passing only the relevant parsed data for recording or validation.

How to Enable Alter Scan

  1. Navigate to the Advanced tab when creating or editing a service.
  2. Select the option to Alter Scan Values and enter:
    • Pattern: A regular expression (regex) to define the portion of the scanned value to extract.
    • Replacement: A regex template that specifies how the extracted data should be formatted.

For further assistance, email our support team with “FROM” and “TO” examples of the data you want to parse.

Using Regex for Custom Alterations

Regular expressions (regex) power the Alter Scan feature, allowing you to precisely define how barcode values are parsed.

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

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”.

Need Help?

If you need help creating regex patterns, contact our support team with examples of the “FROM” and “TO” data. We’ll assist you in setting up the Alter Scan feature to fit your needs.

Optimize your barcode scanning workflows today with this powerful customization tool!