bardecode.com
barcode reading software
  • Home
  • Download
  • Purchase
  • SDK Licensing
  • Pricing
    • Windows SDK Price List
    • Windows SDK with PDF Extension Price List
    • Linux SDK Price List
    • Linux SDK with PDF Extension Price List
    • PDF Extension For Windows Price List
    • Multi-Platform Toolkit for .NET Price List
    • BardecodeFiler Desktop Only Price List
    • BardecodeFiler Windows Service Price List
    • DOS Command Prompt Barcode Tool Price List
    • Terms and Conditions
    • Refund Policy
  • Products
    • Softek Barcode Reader Toolkit for Windows
    • Softek Barcode Reader Toolkit for Linux
    • BardecodeFiler Desktop App
    • BardecodeFiler Windows Service
    • Windows DOS Command Prompt Tool
    • Multi-platform barcode reader toolkit for .NET
    • Aquaforest’s Autobahn DX
  • Knowledge Base
    • Documentation
    • Specifications
  • News
  • Contact
    • About Us
    • Terms and Conditions
    • Resellers
    • Links
Select Page ...

News

Basic regex pattern matching

admin July 22, 2019 BardecodeFiler, Knowledge Base, Software Development Kits

The Softek Barcode Reader SDK and our BardecodeFiler Windows application both use ‘regex’ pattern matching for matching barcode values. We often get asked advice on how to build a regex so we thought a short guide to the basics might be useful.

 

Here is a simple example:

^\d{5}$

So let’s break it down:

^ means the start of the barcode

$ means the end of the barcode

\d means any digit 0 to 9 and the {5} after means that the digit should be repeated 5 times.

So this will match a barcode with value 12345 but will not match 1234 or 123456

If you miss out the ^ and $ symbols then the barcode just needs to contain 5 digits somewhere. In this case a barcode of value 123456 would also match because it contains 5 consecutive digits.

If you want to match between 4 and 6 digits you would use \d{4,6} rather than \d{5}.

You could also use \d+ to match 1 or more digits or \d* to match 0 to any number of digits.

 

In addition to \d you could also use:

\s to match anything that is white space

\S to match anything that is not white space

\D to match anything that is not a digit

\w to match A-Z a-z 0-9 and _ (underscore)

\W to match anything that is not included in \w

 

You can also match a specific set of characters using []. For example, if your barcodes all begin with 3 letters A, B and C in any order followed by 5 digits (e.g ABC12345 or CBA98765) then you could use:

^[A-C]{3}\d{5}$

 

If your barcodes all start with a fixed pattern such as POD, followed say by 8 digits then you would use:

^POD\d{8}$

 

The above hardly scratches the surface of what a regex can do but there are plenty of resources available:

For a more extensive basic guide try the following link:

https://ryanstutorials.net/regular-expressions-tutorial/regular-expressions-basics.php

For testing out your regular expression try:

https://regex101.com/

 

 

 

← A test script for Linux
How to fool ANPR systems →
admin

  • Copyright © 2023 Softek Software Ltd. All Rights Reserved