# Regsubst not picking up the groups

I have a variable with a value : [192.168.12.40] I would like to get rid of the curly brackets, so I decided to use regsubst. And this is how I am using it given that var1=[192.168.12.40]

  $var2=regsubst($var1,'($)(.*?)($)','\2')
notify {"This is the value for ipaddress ${var2} ":}  Unfortunately, this is not returning the correct value that I want which is 192.168.12.40 without the curly brackets. I need help figuring out what am I missing. edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted Hi itaremyinitials, It seems like the main reason for that wrong output comes from the way$var1 was defined, if it is defined without simple quote, then it is most probably interpreted as an array (not as a String), you must have a single quote to make sure that the curly brackets are not interpreted (see the output below).

With this code, I get the correct output

$var1='[192.168.12.40]'$var2=regsubst($var1,'($)(.*?)($)','\2') notify {"This was the value before:${var1} ":}
notify {"This is the value after: \${var2} ":}


Output,

Notice: This was the value before: [192.168.12.40]
Notice: /Stage[main]/Main/Notify[This was the value before: [192.168.12.40] ]/message: defined 'message' as 'This was the value before: [192.168.12.40] '
Notice: This is the value after: 192.168.12.40
Notice: /Stage[main]/Main/Notify[This is the value after: 192.168.12.40 ]/message: defined 'message' as 'This is the value after: 192.168.12.40 '

more

Thanks a lot @stivesso that was it

( 2017-12-27 01:48:50 -0600 )edit