This page last changed on Jan 11, 2014 by fwank.

hi am i having problems getting the regex to split the values returned from a shell command

my shell command returns 3 values space separated all integers as so

90 100 110

i have set the regex to [0-10000]\s[0-10000]\s[0-10000]
to fill the values into 3 sensors temp;press;hum

but the sensor log shows that it is not being split

WARN 2014-01-11 13:19:09,856 : Sensor 'press' (ID = 231,980) is RANGE type but produced a value that is not an integer : '90 100 110'
WARN 2014-01-11 13:19:09,858 : Sensor 'hum' (ID = 231,981) is RANGE type but produced a value that is not an integer : '90 100 110'
WARN 2014-01-11 13:19:09,858 : Sensor 'temp' (ID = 231,979) is RANGE type but produced a value that is not an integer : '90 100 110'

note the shell command is working

ttfn fwank

  • [0-10000] does not look to me like a regexp that would match numbers. [...] defines a range of characters that would be matched. So [a-z] would match any one lower case character, but just one.
  • you need to use groups in your regular expression to capture each individual value
  • easiest is to use a test tool such as this

For your specific case, try

(\d{1,3})\s(\d{1,3})\s(\d{1,3})
, extracting group 1, 2 and 3 as the values.

Posted by ebariaux at Jan 12, 2014 15:01

that works superbly, i had been banging my head for days

thanks again

Posted by fwank at Jan 13, 2014 14:51
Document generated by Confluence on Jun 05, 2016 09:31