# Regex payload string into 6 separate payloads

**URL:** <https://discourse.nodered.org/t/regex-payload-string-into-6-separate-payloads/10309>\
**Category:** General\
**Created:** [17 April 2019 23:44 UTC](https://discourse.nodered.org/t/regex-payload-string-into-6-separate-payloads/10309 "2019-04-17T23:44:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [17 April 2019 23:44 UTC](https://discourse.nodered.org/t/regex-payload-string-into-6-separate-payloads/10309/1 "2019-04-17T23:44:30Z")

</div>

Hi,

I’m really struggling with this one. I’m terrible at regex, and to be honest I’m not sure if that’s the best route either.

Please could someone help me convert the following string (below) ...

> IPH[192][168][222][252] IPR[192][168][222][001] IPN[255][255][255][000] IPHW[7A][CB][E2][60][00][9A] IPP[23] IPDP[Y]

...so I have 6 separate payloads to process

Device IP,  
Default Gateway,  
Subnet Mask,  
MAC Address,  
Port,  
DHCP Y/N,

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 April 2019 00:36 UTC](https://discourse.nodered.org/t/regex-payload-string-into-6-separate-payloads/10309/2 "2019-04-18T00:36:32Z")

</div>

Well for start - ignoring regex, you you use a `change` node and change all `][` to a period. you will have  
`IPH[192.168.222.252] IPR[192.168.222.001] IPN[255.255.255.000] IPHW[7A.CB.E2.60.00.9A] IPP[23] IPDP[Y]`  
then if you use a `split` node and split it using a blank as the 'split using', you will have

```auto
IPH[192.168.222.252]
IPR[192.168.222.001]
IPN[255.255.255.000]
IPHW[7A.CB.E2.60.00.9A]
IPP[23]
IPDP[Y]

```

and you should be able to process each of those messages from there.

---

<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:** [18 April 2019 07:40 UTC](https://discourse.nodered.org/t/regex-payload-string-into-6-separate-payloads/10309/3 "2019-04-18T07:40:27Z")

</div>

Use a function node...

```auto

var temp = msg.payload; // `IPH[192][168][222][252] IPR[192][168][222][001] IPN[255][255][255][000] IPHW[7A][CB][E2][60][00][9A] IPP[23] IPDP[Y]`

temp = temp.trim();
temp = temp.replace(/]\[/g, '.');//replace][ with .
temp = temp.replace(/]/g, ',');//replace remaining ] with ,
temp = temp.replace(/\[/g, ':');//replace remaining [ with :
var spl = temp.split(','); //split by : to get an array of "item:value"
var result = {};//declare object where to put results

spl.forEach(function(item){
  if(item != ""){
    let pair = item.split(":");
    let itemName = pair[0].trim();
    let itemValue = pair[1].trim();
    result[itemName] = itemValue;
  }
})
msg.payload = result;
return msg;

```

[click me for proof](https://repl.it/@StephenMcLaughl/nr-split-proof)
