Regular expression: Difference between revisions
(2 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
=== Regular expression examples === | === Regular expression examples === | ||
Some examples for interpreting a response are: | Some simple examples for interpreting a response are: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
Line 23: | Line 23: | ||
|- | |- | ||
| U_L_N 325 | | U_L_N 325 | ||
| (-?[0-9.,Ee-]+) | | (-?[0-9.,Ee+-]+) | ||
| 325 | | 325 | ||
| Takes the first number. | | Takes the first number. | ||
|- | |- | ||
| I_L1;12.34 | | I_L1;12.34 | ||
| ;(-?[0-9.,Ee-]+) | | ;(-?[0-9.,Ee+-]+) | ||
| 12.34 | | 12.34 | ||
| Takes the first number after ";". | | Takes the first number after ";". | ||
|- | |- | ||
| THD_U_L1;;14,5 | | THD_U_L1;;14,5 | ||
| ;;(-?[0-9.,Ee-]+) | | ;;(-?[0-9.,Ee+-]+) | ||
| 14.5 | | 14.5 | ||
| Takes the first number after ";;". | | Takes the first number after ";;". | ||
|- | |- | ||
| AC_FREQ;Channel1;1. | | AC_FREQ;Channel1;1.23E+3 | ||
| ;.*;(-?[0-9.,Ee-]+) | | ;.*;(-?[0-9.,Ee+-]+) | ||
| 1230 | | 1230 | ||
| Takes the first number after the appearance of a second ";". | | Takes the first number after the appearance of a second ";". | ||
Line 46: | Line 46: | ||
[[File:ValidateExpressionTool.png]] | [[File:ValidateExpressionTool.png]] | ||
In the {{ScreenElement|Regular Expression Tester}}, the following fields are available to verify the regular expression: | |||
{{ScreenElementDescriptionStart}} | |||
{{ScreenElementDescription|Input|Any text that is expected to be returned by the device.}} | |||
{{ScreenElementDescription|Regular Expression|The [[Regular expression]] that is being tested. This regular expression will be used to use the text from {{ScreenElement|Input}} and convert it into a numerical value.}} | |||
{{ScreenElementDescription|Result|The numerical value that is determined by the device driver using the {{ScreenElement|Regular Expression}} on the {{ScreenElement|Input}}.}} | |||
{{ScreenElementDescriptionEnd}} | |||
== Links == | == Links == |
Latest revision as of 10:37, 1 February 2023
A Regular expression is a text pattern that describes how textual input should be parsed to retrieve a piece (or complete) of the textual input.
For regular expression we advise, to learn on how to use regular expressions, at a dedicated internet site. For example: https://www.regular-expressions.info/tutorial.html
An online regular expression tester can also be used to verify the correctness of the regular expression: https://regex101.com/
Configurable device drivers[edit]
In RadiMation® the Regular expressions are often used to interpret the response of a device. Several configurable device drivers, provide a possibility to specify the regular expression to convert the response on a query-command into a value.
The most complete regular expression to retrieve a floating point number from a response is:
([+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?)
The part of the regular expression that is included within the outermost brackets is taken as the final result.
Regular expression examples[edit]
Some simple examples for interpreting a response are:
Received information | Regular expression | Determined measurement value | Note |
---|---|---|---|
U_L_N 325 | (-?[0-9.,Ee+-]+) | 325 | Takes the first number. |
I_L1;12.34 | ;(-?[0-9.,Ee+-]+) | 12.34 | Takes the first number after ";". |
THD_U_L1;;14,5 | ;;(-?[0-9.,Ee+-]+) | 14.5 | Takes the first number after ";;". |
AC_FREQ;Channel1;1.23E+3 | ;.*;(-?[0-9.,Ee+-]+) | 1230 | Takes the first number after the appearance of a second ";". |
The correctness of the regular expression can be tested, verified and improved by using the Validate Expression tool within the configurable device driver.
In the Regular Expression Tester, the following fields are available to verify the regular expression:
Input | Any text that is expected to be returned by the device. |
Regular Expression | The Regular expression that is being tested. This regular expression will be used to use the text from Input and convert it into a numerical value. |
Result | The numerical value that is determined by the device driver using the Regular Expression on the Input. |
Links[edit]
- Wikipedia: Regular Expression
- Regular expression tutorial: http://www.regular-expressions.info/tutorial.html
- Regular epxression tester: https://regex101.com/