Learning regexp

Started by tunkmountainman, May 24, 2020, 02:02:59 PM

tunkmountainman

    Just learning regexp using "Online regex tester and debugger". Tried the regexp from "Watermeter.js" from the new "Metrics"
The tester program does not like the   regexp:/GPM\:([\d\.]+)/i,    It shows the forward slashes as needing to be escaped. Tried several other languages but only Python liked the forward slashes. I know this regexp works because it is used all over in other scripts. What am I doing incorrectly?  There should be an escaped colon after GPM...

tunkmountainman

Just tried  in the "online regex tester and debugger" and it hates the forward slashes, tells me they need to be escaped.

F : { name:'F', regexp:/\bF\:(-?\d+\.\d+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 } }},

What am I doing incorrectly?

TomWS

You need to remove the leading "regexp:".  It is not part of the matching expression so it's thinking the forward slashes are some kind of escape character.

Felix

In Javascript regular expressions variable types do not have any quotes like strings but instead are defined within forward slashes '/' and followed by special designators like case insensitive (the i) etc. In JSON notation, which is found in the metric definitions, a regex variable is defined as:

variableName followed by colon (:) followed by the regular expression itself, ex:

regexp:/GPM\:([\d\.]+)/i


You can test these expressions at regexr.com where they have a very nice UI that helps you with debugging and building/modifying a regex.

tunkmountainman

    Thank you guys you really helped. I have a lot more testing to do. Thank you again.