# Barcode Scanner Input & RegEx

**URL:** <https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 5, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524 "2022-07-05T15:54:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tecnoeletronic](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tecnoeletronic/32/50975_2.png) [@tecnoeletronic](https://forum.inductiveautomation.com/u/tecnoeletronic)\
**Post date:** [July 5, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524/1 "2022-07-05T15:54:11Z")

</div>

Hi,

i need to recognize a barcode using the Barcode Scanner Input.

I need to recognize codes like:

- H1
- H21
- D1
- D5
- P1
- P12

The follow RegEx doesn't work as aspected.

> ([HDP]\d{1,}){1}

It recognize the First Letter and only the First Number so the "H1" and the "H12" return only H1..  
I tried a lot of RegEx but with not success...

What i'm doing wrong?

---

<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:** [July 5, 2022, 3:58pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524/2 "2022-07-05T15:58:13Z")

</div>

I would expect a regex of `([HDP]\d+)` to work.

> **[regex101: build, test, and debug regex](https://regex101.com/r/DyNaIn/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.

---

<div class="post-metadata">

**Author:** ![tecnoeletronic](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tecnoeletronic/32/50975_2.png) [@tecnoeletronic](https://forum.inductiveautomation.com/u/tecnoeletronic)\
**Post date:** [July 5, 2022, 4:06pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524/3 "2022-07-05T16:06:47Z")

</div>

No, it doesn’t work. I already tried a lot of time… It return only First Letter and First Digit… 🥲

---

<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:** [July 5, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524/4 "2022-07-05T16:14:07Z")

</div>

Ah. Try this: `([HDP]\d+)Enter`

The regex match is returning as soon as the first match is found, not waiting for more input. If your scanner is configured to terminate the scan with a keypress of Enter, you can capture that (_outside_ of the group) and it will work:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/731ef954a91d160c5b8e836a53fe2c69217e42bd.png)

---

<div class="post-metadata">

**Author:** ![tecnoeletronic](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tecnoeletronic/32/50975_2.png) [@tecnoeletronic](https://forum.inductiveautomation.com/u/tecnoeletronic)\
**Post date:** [July 5, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524/5 "2022-07-05T16:14:24Z")

</div>

To solve this problem at the moment i added a PREFIX and SUFFIX in Scanner Data Output like:

- pre: @
- suf: #

The RegEx work in this case…

---

<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:** [July 5, 2022, 4:15pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-regex/61524/6 "2022-07-05T16:15:22Z")

</div>

If you’re using prefix or suffix, the regex property is ignored. If your barcodes end in `#`, you could use that with the updated regex I posted above, just replace `Enter` with `#`.
