# How to parse data from a String in a Buffer

**URL:** https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781
**Category:** General
**Created:** [16 January 2023 20:19 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781 "2023-01-16T20:19:37Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)
#### Post date: [16 January 2023 20:19 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781/1 "2023-01-16T20:19:37Z")

</div>

Hi,

I try to support someone with an Optical reader from Weidmann Elektronic (German Device).  
He is able to receive data as shown in a picture below.

![Screenshot_Weidmann_Output](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/67dad3a98ea378d230aee08cc07f61e59fa104e8.png)

One would expect, that you can read the output with the Smartmeter node.  
Obviously this was not the case.

The lines he (and so do I) is interested in are the lines with the OBIS references 1-0:1.8.0 until 1-0:2.8.2.

The question is: How to isolate these 6 lines and put them in an object?

I do not own such a device myself, so it is difficult to test and to build a simulation with a Inject node.

I hope someone can give me a hint, about which way to go

Thanks in advance

Regards

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [16 January 2023 20:34 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781/2 "2023-01-16T20:34:38Z")

</div>

This usually is a job for a Regular Expression.  
Some Links that might be helpful: [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), [RegExr](https://regexr.com/) - a playground, a [recent post to a similar topic](https://discourse.nodered.org/t/how-to-pass-a-regex-into-a-function-node/67701).

---

<div class="post-metadata">

### Author: ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)
#### Post date: [17 January 2023 11:06 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781/3 "2023-01-17T11:06:24Z")

</div>

Hi @ralphwetzel,

Thanks for the response. Although I'm do not consider myself as a specialist on Regular Expressions, I will look into it and see what will come out of it.

Regards

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [17 January 2023 11:19 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781/4 "2023-01-17T11:19:54Z")

</div>

> [@FireWizard52](#):
>
> I hope someone can give me a hint, about which way to go

If you want someone to really help, i would advise that you paste the actual buffer values (instead of a picture) so whoever helps has some real data to play with. Use the "copy value" button that appears when you hover over the debug payload.

### CANNED TEXT

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [17 January 2023 11:42 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781/5 "2023-01-17T11:42:54Z")

</div>

> [@FireWizard52](#):
>
> Although I'm do not consider myself as a specialist on Regular Expressions

Have you ever seen an "expert on regular expressions"? 😉  
For me it's always try & error ... & error & ...

---

<div class="post-metadata">

### Author: ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)
#### Post date: [17 January 2023 12:49 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781/6 "2023-01-17T12:49:46Z")

</div>

Sorry @Steve-Mcl,

Sorry for that, I know how to do that and I also saw the docs, although this is some time ago.

As said, I try to support someone else and this is what I got so far.  
I do not own that Weidmann device, so I can't test and do not have the original output.

The user sent me already a file with was redirected from the original output and this file gave me the exact same result as my simulation. But this file (and my simulation) is a string, while it looks that the original output from the Exec node is a buffer, containing a string.

I tried to create a simulation with an Inject node. However the simulation in the Inject node does not seem to be identical as the output of the device. With the simulation I can achieve what I wanted so far. But testing on the real device failed.

However I appreciate your response and your nice videos.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 March 2023 12:49 UTC](https://discourse.nodered.org/t/how-to-parse-data-from-a-string-in-a-buffer/73781/7 "2023-03-18T12:49:59Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
