-1

I am successfully validating an ID such as:

ZFA1G2H34J5K6L7P5

using this regex:

([a-h,A-H,j-n,J-N,p-z,P-Z,0-9]){17}$

This ID sometimes arrives corrupted (comes from a OCR process) and therefore the previous regex does not work. I need to support the most common way of corruption which is having a space within the ID:

ZFA1G2H34 J5K6L7P5

The regex should remove the space and compose just the allowed 17 chars of the ID.

Please note I cannot use scripting (.replace for example) because the software where this regex is used does not support it.

As a bonus, sometimes the ID contains trailing chars which I would like to remove as well:

ZFA1G2H34 J5K6L7P5...ç

JPG
  • 545
  • 3
  • 19

1 Answers1

0

You can use one of the following regular expressions to validate the query:

^(?:(?![iIoO])[ ç0-9a-zA-Z]){17,}$
^([ ça-hA-Hj-nJ-Np-zP-Z0-9]){17,}$

And then, you can use the following regular expression to only match characters you like:

(?:(?![iIoO])[0-9a-zA-Z])
[a-hA-Hj-nJ-Np-zP-Z0-9]

Don't use , in a set like [A-Z,a-z], because commas are actually part of the set and not a separator between the character ranges.

ssc-hrep3
  • 15,024
  • 7
  • 48
  • 87