Regex to select parts of a string

Not a regex expert, but I have a query that returns the following string.

(**MACHINE: OKUMA LB3000 *)(**DATE: 8/22/2024 *)(**W/O:W62502**LOT:1**OP:40 *)(**P/N:32205 *)

I can extract the value after W/O: with this regex regex = /[W][0-9]{5}/ but I cannot see to get any other values like all the numbers after P/N:, using tools like regex101 I have this regex (?<=P/N:)\d+(?=\s) but it tells me ? The preceding token is not quantifiable

How can I break this string down so I can get some of the values after the :? Is regex the right way to go about this?

Hello @fastxl,
Can you share the Flux query you have so far?
Is this a field?

How are you ingesting?
You might want to considered doing some of this processing before writing to InfluxDB (recommended) :slight_smile:

This is a field and this query gets me the value after W/O:. The field is actually much longer than what I have shown.

import "regexp"

regex = /[W][0-9]{5}/

from(bucket: "DE-CNC")
    |> range(start: -2d, stop: now()) 
    |> filter(fn: (r) => r._value != "UNAVAILABLE")
    |> filter(fn: (r) => r["deviceId"] == "Okuma-LB3000")
    |> filter(fn: (r) => r["dataItemId"] == "Lp1ProgramHeader")
    |> filter(fn: (r) => exists r._value)
    |> map(fn: (r) => ({r with _value: regexp.findString(v: r._value, r: regex)}))
   |> yield(name: "Last")

I am ingesting through a custom adapter that is reading data from a CNC Machine. Not sure if I can do some processing before, but I will look into it.

I am looking to report some of these values in Grafana to a single stat panel.