Regular Expressions 101

Community Patterns

Product Code Matcher

1

Regular Expression
Python

r"
(?:[^-A-Z0-9\.\/\\£]|\A) [\.#]? ( (?!\d{2}[-\\/]\d{2}[-\\/]\d{2,4}) (?=[A-Z\.\/\\]*?\d) [-A-Z0-9\.\/\\]{3,10}[A-Z0-9]s? ) (?:[^-A-Z0-9\/\\]|\Z)
"
gax

Description

Regex to find product codes that are usually all upper case with numbers or all numbers with possible hyphens, slashes or dots as delimiters.

Anything that matches the date format ##/##/##?? with various delimiters will not match.

Require that the code contains at least 1 number.

The code can optionally end in a lower case s.

Submitted by anonymous - 7 years ago