Parse String. Regex?

Hi.

I have a sting output that I want to split somehow. Have tried a few regex expressions but i have early used regex before so no luck. Any idea how to do this the best way?

the string lock like this ALARM,A:341N572964E012045499 A12002172140U AlarmButton R:5 B:4 G:F;

I want this to be splitted so it looks something like this

ALARM
A:341
N532464
E014075491
A12002172140U
AlarmButton R:5 B:4 G:F;

If you use JSONata, you can use the following expression and you will get back an array containing the results:

$match(payload, /(.*),(.*)(N.*)(E.*)(A.*) (A.*)/).groups
1 Like

Wow!! Thanks!!

1 Like

One more question. $match(payload, /(.),(.)(N.)(E.)(A.) (A.)/).groups works fine. But if I want to remove N and E in the result can I do something like $match(payload, /(.),(.)(N.-1)(E.-1)(A.) (A.)/).groups have tried o lot of combinations but can not get the formatting right. If it works to do something like that?

Not tried but probably something like:

$match(payload, /(.*),(.*)N(.*)E(.*)(A.*) (A.*)/).groups

When working with regex, the regex101 website is a powerful tool to see if you’ve configured it correctly. It supports multiple languages’ flavour of regex, so make sure to set it to JavaScript first. On top of that it has a reference included for all functionality.
Here’s Julian’s last regex, and I think it would work well: https://regex101.com/r/TjwEID/1/

It matches as:

Group 1. n/a ALARM
Group 2. n/a A:341
Group 3. n/a 572964
Group 4. n/a 012045499
Group 5. n/a A12002172140U
Group 6. n/a AlarmButton R:5 B:4 G:F
1 Like

Yes, I regularly use various online regex tools for more complex requirements. This one was fairly easy and didn't need anything clever :grinning:

Thanks!! You guys are awesome :+1:

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