# Filter the barcode scanner input data and bind the newest barcode to a component

**URL:** <https://forum.inductiveautomation.com/t/filter-the-barcode-scanner-input-data-and-bind-the-newest-barcode-to-a-component/73699>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [May 14, 2023, 11:14pm UTC](https://forum.inductiveautomation.com/t/filter-the-barcode-scanner-input-data-and-bind-the-newest-barcode-to-a-component/73699 "2023-05-14T23:14:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![uy\_huynh](https://avatars.discourse-cdn.com/v4/letter/u/54ee81/32.png) [@uy\_huynh](https://forum.inductiveautomation.com/u/uy_huynh)\
**Post date:** [May 14, 2023, 11:14pm UTC](https://forum.inductiveautomation.com/t/filter-the-barcode-scanner-input-data-and-bind-the-newest-barcode-to-a-component/73699/1 "2023-05-14T23:14:35Z")

</div>

Hi all,  
I have the following barcode data: Shift01093165040877083075]Control10 **M** Shift **F** Shift **00001416** ]Control912124682  
How can I set up the barcode input component that only takes the MF00001416, and bind/replace the newest barcode to text area.  
I've tried to use the property binding, but the data set is array so it stores everything in the area.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/9/f909efbd96a71fff9c407d0c28b05093189e524b.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 15, 2023, 3:57am UTC](https://forum.inductiveautomation.com/t/filter-the-barcode-scanner-input-data-and-bind-the-newest-barcode-to-a-component/73699/2 "2023-05-15T03:57:37Z")

</div>

Within the Barcode Scanned (Session) Event, I would use a regex to parse out only the information you want from the incoming value and then write that to a session property or tag, depending on if this data is relevant to only a session or anyone using the project. Then, I'd bind the display value against that session property.

```auto
import re
session.custom.barcode = re.search(regular_expression_here, data.text)

```

---

<div class="post-metadata">

**Author:** ![uy\_huynh](https://avatars.discourse-cdn.com/v4/letter/u/54ee81/32.png) [@uy\_huynh](https://forum.inductiveautomation.com/u/uy_huynh)\
**Post date:** [May 15, 2023, 4:14am UTC](https://forum.inductiveautomation.com/t/filter-the-barcode-scanner-input-data-and-bind-the-newest-barcode-to-a-component/73699/3 "2023-05-15T04:14:21Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/1/51260e6ca68d5fabc337189620f11ed213360307.png)  
Am I doing it right? Because I;m still seeing this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/d/cd828528c7c61ef75a153ab3859ccb98fd51727d.png)

---

<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:** [May 15, 2023, 1:04pm UTC](https://forum.inductiveautomation.com/t/filter-the-barcode-scanner-input-data-and-bind-the-newest-barcode-to-a-component/73699/4 "2023-05-15T13:04:41Z")

</div>

You can use a site like [regex101.com](http://regex101.com) to test your regexes:  
Link for your case: [regex101: build, test, and debug regex](https://regex101.com/r/bdfCP2/1)

```python
def onBarcodeDataReceived(session, data, context):
	import re
	
	result = re.search(r'(Control.*?\b)', textIn)
	
	if 'groups' in dir(result):
		session.custom.barcode = result.group(0)
	else:
		session.custom.barcode = 'Not Found!'

```

Test:

```python
import re
textIn = 'Shift01093165040877083075]Control10MShiftFShift00001416]Control912124682'

search = re.search(r'(Control.*?\b)', textIn)

if 'groups' in dir(search):
	print search.group(0)
else:
	print 'Not found!'

```

Output:

```plaintext
Control10MShiftFShift00001416

```
