Barcode Scanner Regex Excluding 'Enter'

I am attempting to use a Session Event, Key Event using regex to capture a barcode scan from a physical barcode scanner. I am currently using the regex: ^(?!Enter)([A-z0-9]{9})

When checked using regex101, this regex should work for the scanners resulting input. Yet, 'Enter' seems to be getting passed the regex and into the resulting string. (As seen in the image below).

Barcode_Scanner_Results

regex101_check

Any recommendations would be greatly appreciated.

This is a bit confusing. the Regex101 works because the word 'Enter' does not appear in the test string.

Are we talking about the word 'Enter' or are we talking about a carriage return?

Session key events are weird, because JS key events are weird.

Does your regex just need to be ^[A-z0-9]{9}Enter$?

Also note that forward assertions in regex do not consume the characters involved.

Thank you for the response. When testing in Regex101 it seems to be read as a carriage return. Yet, in Perspective it seems to be read as the word 'Enter'. Thus everything I have tried seems to pass tests in Regex101 but fails when using the session events in Perspective.

Thanks for the response. Unfortunately the regex you suggested does not pass in either the Regex101 or Perspective. I have limited experience with regex so it isn't fully clear as why. An updated version of your suggestion, ^[A-Za-z0-9]{9}(Enter|\r|\n)$, passes in regex101 but still not as a session event in Perspective. This version passes in regex101 due to the newline addition, '\n'.

This may be a very crude method but the following regex seems to ignore 'Enter' yet still allows for any scans with any of the character, ^(?!.*Enter)(?!.*nter)(?!.*ter)(?!.*er)(?!.*r)[A-Za-z0-9]{9}$. If anyone sees any concerns with using this please let me know.

Are there always nine characters before Enter, or is it variable? Asking because you're showing four characters before Enter in your pic, but the regex is requiring nine characters.

If it's variable, you could modify the one Paul posted to

([A-z0-9]{0,})(Enter)$

image

1 Like

http://regex.info/blog/2006-09-15/247

1 Like