Use Regular Expression Examples

Pattern

Description

Comment

S(?<value>.*)

All characters after the leading "S".

We encountered barcodes with an extraneous "S" on cartons shipped by HP. This pattern says: “If a value starts with S, it’s a serial number, and the actual serial number is every character after the leading “S”. This is probably too broad for general use because you have other assets with serial numbers that legitimately begin with “S” and you don’t want the “S” stripped in those cases. To get around this, we’ve given HP assets their own form that will be used exclusively for HP assets.

Ideally, you could define a much tighter pattern like “HP serial numbers are always ”SCN + 8 characters, and strip off the leading S”. That would probably be specific enough so that HP assets wouldn’t need their own form. That pattern would be S(?<value>CN.{8})

Simpler as a prefix!

This is an example of a pattern that is simple enough to be implemented as a prefix instead of a pattern, but it's shown here because it's a simple example of a pattern.

Sample values:

  • SCNC819R159
  • SCNC819R10R
  • SCNC819R155
1S.+1U(?<value>.*)

All characters that follow “1U”

This is an IBM pattern that is much more specific than the HP pattern. It says: “If a value starts with ”1S, then is followed by 1 or more characters, then “1U” followed by zero or more characters, it’s a serial number, and the actual serial number is every character after “1U”.

This pattern is specific enough that it’s very unlikely that you’ll run into any barcodes that share this pattern that aren’t IBM serial numbers. Thus we’re probably safe to not have a dedicated IBM form.

Sample values:

  • 1S679021UKA87DND
  • 1S679021UKA10RPG
  • 1S679021UKA70CTM
 (?<value>Q\d{10})[A-Z]{1}

All characters except the last capital alphabet letter

We saw this pattern for some Ricoh products. “Every character except the last character” doesn’t allow us to discriminate between anything that’s scanned, so we tightened this up to express “If a value starts with Q followed by 10 digits followed by an uppercase alphabet character, it’s a serial number and the actual serial number is everything except the last character.”

Like the IBM pattern, this pattern is probably specific enough that we’re unlikely to encounter any barcodes that fit the pattern that aren’t Ricoh serial numbers. So in the sample form, it shares the same form as the IBM pattern.

Sample values:

  • Q3389300726O
  • Q3389300729R
  • Q3389400331H
(?<value>SL\d{7})

Return only SL followed by 7 digits

 

AA(?<value1>\d+)BB(?<value2>\d+)AA.*

Stripping & concatenation

You can specify multiple values to concatenate by adding a numeric suffix to the "value", for example, if the following pattern was specified for the Asset Tag field:

AA(?<value1>\d+)BB(?<value2>\d+)AA.*

... and you scanned the barcode AA11BB22AA000, AssetTrack would:

  1. Detect that the scanned value matched the pattern specified for the Asset Tag field and therefore placed the resulting value into the Asset Tag field regardless of which field is currently focused.
  2. Extract two substrings based on the regular expression.

The resulting value placed into the configured field would be 1122.

AA(?<value>\d)AA

Value from the middle of a string

Using the specified pattern would take the value AAFoobarAA and strip it down to Foobar.

 

^(?<value>\d{3}\.[a-zA-Z]{1}\d{2}\.[a-zA-Z]{1}\d{2})$|^(?<value>\d{1}[a-zA-Z]{1}-\d{3}\.\d{2})$

Long scan pattern with terminator

This pattern used for BDC Room field

Note this patter for three concepts:

  1. Specifies an elaborate pattern using alpha-numeric, numeric and dot characters Note: The backslash escapes the dot character

2.      Has a $ to terminate (limit) the last input characters (used for data policies)
Ex: 123.A12.B12 vs 123.A12.B12000000000

  1. Uses the | character to OR two patterns
    Ex. User can specify 123.A12.B12 or 1Z-123.45

^(?<value>(BE|BA)\d{6})$|^(?<value>(BZ).*)$

Another OR pattern

Used for BDC Asset Tags.

This is used for the Data Policy to allow either/or as specified on each side of the | (pipe) character.

The .* is sued to allow any type or number of characters.

Examples

  • BE123456
  • BA123456
  • BZ12WE34RT

 

(1S[0-9]{7})(?<value>[A-Za-z]{7})

Return only the last 7 characters when the string is 1S + 7 digits + 7 characters

This pattern illustrates that characters or digits that are desired to be scanned in, must reside within the (?<value>)... parenthesis.  And characters or digits desired to be trimmed should be outside of the (?<value>).

As you have seen in other pattern examples if you intend to trim literal characters place them outside of the (?<value>).

Ex: AA(?<value>[A-Za-z]{7})

In this case the letters AA will be trimmed from the scan. 

For this pattern (1S[0-9]{7})(?<value>[A-Za-z]{7}) we want to trim the 2 literal values 1S and 7 digits which makes this more complicated than just the  literal AA above, and therefore it is required that this piece of the expression be wrapped in parenthesis. (1S[0-9]{7})

Sample values:

Barcode value

Value that will appear in the scanner

1S1234567ABCDEFG

ABCDEFG

1S1234567AbCDEfG

AbCDEfG

1S9090902DFDSFnt

DFDSFnt

(?<value>2[4-9][0-9][0-9][0-9])

Only allows a five digit number between 24000 and 29999.

 

 

Have more questions? Submit a request

Comments

  • Avatar
    John E Mcconnell

    I'd like to get a rule that errors on a serial number when people say things like UNKNOWN or (wildcard)DUP

Please sign in to leave a comment.