Finding non-conforming barcodes in Sierra

I’m trying to find non-conforming barcodes in Sierra using Create Lists. I’ve been able to use Matches (R) and RegEx to find barcodes with non-numeric characters that we need to fix, but I’m unable to find a RegEx that works to identify barcodes that are either too short or too long. For reference, our barcodes are 14 digits, numbers only. I have tried any number of RegEx variants sourced from the web trying to get character counts to work, and I can’t even get Sierra to return barcodes with 0-9 of 14 characters, which should be 99% of our barcodes. Any ideas what I’m doing wrong? Here’s the basic query to try and match 14 characters that doesn’t work

^[0-9]{14}$

Any thoughts? Or will I just need to use SQL for this?

EDIT: Turns out even a simple query like this needs (?e) in front of it. And in a non-optimal way, I did manage to get the queries to work.

Fewer than 14 digits: (?e)^[0-9]{1,13}$
Greater than 14 digits:(?e)^[0-9]{15,99}$

I’m not 100% sure how this works, but I’ve cobbled together the following that works in a regex tester. I’m not on Sierra, so I can’t guarantee it works with Sierra’s regex engine.

/^((?!^\d{14}$).)*$/gm

Here is how ChatGPT thinks it works:

The given regular expression, /^((?!^\d{14}$).)*$/gm, is a regex pattern with the following components:

  1. /: Delimiters indicating the start and end of the regular expression.
  2. ^: Matches the start of a line.
  3. (: Begins a capturing group.
  4. (?!: Starts a negative lookahead assertion, which means it will match if the specified pattern does not match at the current position.
  5. ^: Matches the start of a line.
  6. \d{14}: Matches exactly 14 digits.
  7. $: Matches the end of a line.
  8. ): Ends the negative lookahead assertion.
  9. .: Matches any character except a newline.
  10. )*: Quantifier that matches zero or more occurrences of the preceding group.
  11. $: Matches the end of a line.
  12. /: Delimiters indicating the end of the regular expression.
  13. g: Global flag indicating that the regular expression should be applied to all occurrences rather than stopping after the first match.
  14. m: Multi-line flag indicating that the ^ and $ anchors should match the start and end of each line within a multi-line string.

In summary, this regex pattern matches any line that does not consist of exactly 14 digits. The ^ and $ anchors ensure that the entire line is checked, and the negative lookahead (?!^\d{14}$) ensures that the line does not match a sequence of 14 digits from the start (^) to the end ($). The g and m flags enable the pattern to be applied globally across multiple lines.

Speaking of ChatGPT it suggested this which I think is more readable:

/^(\d{0,13}|\d{15,})$/gm
OR
/^(?!\d{14}$).*$/gm

Hi Brandon:

Former Sierra admin here, I used the following RegEx snippets for the same purpose:

Fewer than 14 digits: (?e)^.{1,13}$
Greater than 14 digits: (?e).{15}

I got those from Richard Jackson’s Playing with Matches sessions. His latest one on the forum is from 2021. The second post at that link gives his handout and presentation (where he talks about min / max functions and uses patron barcode length as an example).

1 Like