# Barcode Scanner Regex Excluding 'Enter'

**URL:** <https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [June 16, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161 "2023-06-16T19:39:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [June 16, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/1 "2023-06-16T19:39:29Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/37a3ea24f8f0f55363beaada5583cb8c0fd44252.png)

![regex101_check](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/16febeee2f659a87bd252abd3d450dcba4c2e08c.png)

Any recommendations would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 16, 2023, 8:14pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/2 "2023-06-16T20:14:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 16, 2023, 8:20pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/3 "2023-06-16T20:20:49Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 16, 2023, 8:44pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/4 "2023-06-16T20:44:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [June 19, 2023, 12:12pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/5 "2023-06-19T12:12:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [June 19, 2023, 12:20pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/6 "2023-06-19T12:20:34Z")

</div>

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'.

---

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [June 19, 2023, 12:53pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/7 "2023-06-19T12:53:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 19, 2023, 3:24pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/8 "2023-06-19T15:24:03Z")

</div>

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

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

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/1/5147fdd6cb2f5dbb3d48523f52d046e83c1a9bb2.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/0/70857e10dd8daa0b73f7d996af2899a56b0b8d24.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 19, 2023, 4:18pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-regex-excluding-enter/75161/9 "2023-06-19T16:18:28Z")

</div>

> **[Perl Problems](https://xkcd.com/1171/)**
>
> To generate #1 albums, 'jay --help' recommends the -z flag.

[http://regex.info/blog/2006-09-15/247](http://regex.info/blog/2006-09-15/247)
