Help with regex (I think)

Hi guys. You all helped with my last regex style question and hopefully you can do it again.
I am monitoring messages and some have a set of coordinates in it and some dont

,SHELLHARBOUR COUNCIL (NSW),2529 - [150.843460083008,-34.6033782958984]

is an example of the ones that do. How can I check if they are present and secondly, extract them out?

I can do it by looping looking for { , and ] but I think there should be a much easier way

Use a switch node, set the message path to where the pertinent information is. Go to the message on the right there will be 3 icons one will say copy message path. Then set the unique words to an output.

With the format you showed us this should work:

[{"id":"9fd5c36b0660ab65","type":"function","z":"c513d12c.45645","name":"","func":"\nconst regex = /.*\\[(-?[\\d\\.]+),(-?[\\d\\.]+)/;\nconst found = msg.payload.match(regex);\nif(found != null){\n    msg.lat = found[1];\n    msg.lon = found[2];\n    return [msg, null];\n}else{\n    return [null,msg]\n}\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":1720,"wires":[["87e6e9d137a4bea6"],["25b4c4844d748e54"]]},{"id":"921b07b701682dc7","type":"inject","z":"c513d12c.45645","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":",SHELLHARBOUR COUNCIL (NSW),2529 - [150.843460083008,-34.6033782958984]","payloadType":"str","x":340,"y":1720,"wires":[["9fd5c36b0660ab65"]]}]

The function node has this code:

const regex = /.*\[(-?[\d\.]+),(-?[\d\.]+)/;
const found = msg.payload.match(regex);
if(found != null){
    msg.lat = found[1];
    msg.lon = found[2];
    return [msg, null];
}else{
    return [null,msg]
}

The upper debug will get triggered if there is a lat lon in the payload.
If not then the lower will be triggered.

Thank you. I will give it a go.

Works well. I use Node-Red and an HTTP in node and add the stuff to a database if there is geo coordinates it as the lat and lon.

I am googling how to work this regex but its not siking in. Now I have a space in the string as in
-32.7673639999999,152.078141 0 and I need to get out lat, lon and the last number (in this case being zero)
Is there a good tutorial on the net so I dont have to come back and keep asking?

edit: I found a page and came up with .*(-?[\d.]+),([\d.]+) (\d+)

I would use:

.*(-?[\d.]+),([\d.]+)\s+(\d+)

Where \s+ means any whitespace with the length of 1 or more.
Had it been \s* it would mean an optional whitespace of any length.
Sometimes a space is not always a space, but \s will take them all.

I usually use: regex101: build, test, and debug regex or PHP Live Regex depending on what kind of regex I’m building.
They have different advantages as I see it.

Thanks you. Yes once I found a page that added explanations as you typed it become easier. Much better