Article sections

    Alter Scan Value

    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.

    Example Outline

    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.

    Here is an example using real numbers. Let’s say the barcode has 10 characters and I want to remove the first 2 and last 3 characters, keeping the middle 5.

    Example A

    Pattern:

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

    Replacement:

    $1

    Pattern breakdown: given value ‘AB34567CDE’, how does it become ‘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.

    The exact same thing as Example A could be achieved where all three sections are grouped but only one is used:

    Example B

    Pattern:

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

    Replacement:

    $2

    For Example B you see that we changed the replacement to $2 because the five character match is now the second group and we don’t want the first and third groups.

    Example C

    Pattern:

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

    Replacement:

    $1

    For Example C 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_].

    Option:  If you need to get specific you can remove the any of the character types a-z or A-Z or 0-9 or _.

    Pattern:

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

    Replacement:

    $1

    Example D

    Pattern:

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

    Replacement:

    $1

    In Example D 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.

    Example E

    Pattern:

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

    Replacement:

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

    In Example E we want to replace part of a URL.

    From:   https://example/FROM_THIS.php?token=abcdefghij

    To:       https://example/TO_THIS.php?token=abcdefghij

    The regex replaces ‘FROM_THIS’ with ‘TO_THIS’ and all else remains the same.

    Example F

    Pattern:

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

    Replacement:

    x$1 (where ‘x’ is the prefix to add)

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

    From:   1234567890

    To:     A1234567890

    The regex adds the ‘A’ to actual barcode scanned ‘123567890’

    Example G

    Pattern:

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

    Replacement:

    $1

    For Example G the scanned barcode value ‘http://example.com/assets/A42V9.html’ would then be altered to show just the value A42V9. In this way, your codeREADr.com validation database could have either the whole URL in column 1 or just the parsed value and still be valid.

    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)
    Note: Bold italic means replace with your base URL.

    Example H

    Pattern

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

    Replacement

    $2

    For Example H the regex will remove the prefix ‘(00)’ and ‘(J)’ from the scanned barcode and keep any numeric or characters after those. Note the ‘\’ escape before each of the parentheses which are needed within the ( ) structure.

    Example I

    Pattern

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

    Replacement

    $2

    For Example I the 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.

    Example J

    Pattern

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

    Replacement

    $1

    For Example J the regex will remove the first character of the scanned barcode. If you want to specifically target a number or letter you would substitute [\s\S] with the characters you want to remove. So for example, let’s say you wanted to remove upper and lower case ‘aA’.  In that case the pattern would be ^[aA]{1}([\s\S]*)$.

    Example K

    Pattern

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

    Replacement

    B$1

    For Example K the 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’.

    Example L

    Pattern

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

    Replacement

    $1

    For example L 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]

    Example M

    Pattern

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

    Replacement

    $1

    For Example M the regex will remove the “|” and all the characters after that. So for example “12345|text|text” will become just “12345”.

    Example N

    Pattern

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

    Replacement

    $1

    For Example N the regex will remove the “X” prefix but leave all the characters after that. So for example “X12345” will become just “12345”.

    Example O

    Pattern

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

    Replacement

    $1-$3

    For Example O the result 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”.