Transform data - Rename fields by regex

Version: Grafana v11.2.2+security-01 (dc86a9eafb)
Hello,
what is the correct match to rename:

kostal-piko-ba.0.Power.AC1Voltage
kostal-piko-ba.0.Power.AC2Voltage
kostal-piko-ba.0.Power.AC3Voltage

to

L1
L2
L3

I try:
Match: /kostal-piko-ba.0.Power.AC(\d)Voltage/
Replace: L$1

but nothing happens.

Best regards
Marco

Welcome @marcofischerhessberg to the Grafana forum.

I believe the dot . is a special character in regex that matches any single character. To match a literal dot, I believe you might need to escape it using a backslash \. So, \. matches a literal “.”.

Does this work?
Match: /kostal-piko-ba\.0\.Power\.AC(\d)Voltage/
Replace: L$1

Hello grant2,
thanks for your reply.

Unfortunately no effect:

I noticed from your screenshot above that you have the word “value” at the end. Pretty sure you need to include that in your Regex.

Maybe /kostal-piko-ba\.0\.Power\.AC(\d)Voltage value/

Keep fiddling around with it. I am sure there is a way to do this.

Hello grant2,
thanks for your reply.

No effect, “value” is not a part of the field name

Try Match

.*AC(\d).*

Replace

L$1

Dont think your regex needs to be so granular. Try above.
I tested this in my lab by extracting a digit from an IP address and then added your naming scheme using a replace and then doing a second replace to work with your requirement (above).
Not stating the obvious though, as your screenshot doesnt show, but confirm the transform is enabled. (number of times I forgot to re-enable in testing something). The other thing is if you have leading/trailing spaces that are not obvious.
Running Grafana 11.4

Hello russellparker,
thanks for your reply.

Unfortunately no effect:

image

Match: .Power.AC(\d)Voltage.
Replace: L$1

  • .* handles any prefix before Power.AC1Voltage, including “kostal-piko-ba.0”.
  • \. is used to escape dots in regex (because . matches any character).
  • (\d) captures the AC number (1, 2, 3).
  • .* at the end handles any suffix (like value) Grafana might be adding.
  • L$1 uses the captured group (1/2/3) and turns it into L1, L2, L3.

string manipulation using string function in flux is also another approach.

try doing it natively in flux language using a combination of strings.substring() function

and
strings.replace() function

|> map(fn: (r) => ({r with _value: strings.replace(v: r._value, t: "p", u: "XX", i: 2)}))
1 Like

Hello infofcc3,
thanks for your replay.

Unfortunately no effect:

Hello yosiasz,
thanks for your reply,

I will try it.