DanielT / a2ltool

A tool to edit, merge and update a2l files
Apache License 2.0
46 stars 15 forks source link

how to use regex to generate with many style parameter #20

Closed xRowe closed 7 months ago

xRowe commented 8 months ago

Hello again

There is a elf file, the calibration or measurement parameter using different name style.

I am trying to using regex to generate a2l from elf. But .?_Cal is working but (.?_Cal |.*?_Write) will not work correctly.

How can I will regex to match many styles?

Many Thanks

DanielT commented 8 months ago

Hello,

1) You could simply use the parameter --measurement-regex several times on the command line instead of joining the patterns with "|". Each pattern from the command line is checked separately, and a variable is inserted if any of them matches. 2) Your patterns are not ideal, they could be simplified by deleting ".?" and ".*?". The regex engine will report a match if any substring matches your input regex. For example, "_Cal" matches "My_Cal_Variable" 3) You should still be able to use "|" in your patterns, this is a supported feature. I would suggest using extra () around the groups, and you could also test your patterns in advance using one of the regex testing websites

xRowe commented 7 months ago

Thanks for you quick action. Sorry for the late reply.

I tried 1). It works.

But when I tried 3), It does not work, Below are the error I got.

D:\Users\n95\Desktop\a2ltool-1.6.0>a2ltool --create --elffile Test_APP.elf --characteristic-regex _Cal|_Write  --output output.a2l
'_Write' is not recognized as an internal or external command,
operable program or batch file.

D:\Users\n95\Desktop\a2ltool-1.6.0>a2ltool --create --elffile Test_APP.elf --characteristic-regex _Cal (_Cal|_Write)  --output output.a2l
'_Write)' is not recognized as an internal or external command,
operable program or batch file.

D:\Users\n95\Desktop\a2ltool-1.6.0>a2ltool --create --elffile Test_APP.elf --characteristic-regex _Cal (_Cal)|(_Write)  --output output.a2l
--output was unexpected at this time.

D:\Users\n95\Desktop\a2ltool-1.6.0>a2ltool --create --elffile Test_APP.elf --characteristic-regex _Cal ((_Cal)|(_Write))  --output output.a2l
) was unexpected at this time.

Thank you in advance for your great help Rowe

DanielT commented 7 months ago

Your problem is actually really simple: You didn't put "" around your regex, so the | symbol is interpreted by your shell as a pipe symbol.

This should work:

a2ltool --create --elffile Test_APP.elf --characteristic-regex "_Cal|_Write"  --output output.a2l
xRowe commented 7 months ago

Thank you. It does work now