puppet regular expression trouble

I fought an issue recently with puppet regular expressions that I thought I would share. To understand what I was doing, consider this example fact on a server managed by puppet.

mylist => foo:bar:baz

My module needed to query the server and determine if the list of things in that fact matched its list from hiera.

 - 'foo'
 - 'bar'
 - 'baz'
 - 'qux'

Puppet would see qux as missing run the steps necessary to add it to the server. On the next run, the fact contains qux so no more work is needed. I spent some time working on variations of regular expression matching, but could never get it to work.

if "${::my_list}" =~ /$word/ {
  notify { "${::my_list} has ${word} in it": }
else {
  notify { "${::my_list} doesn't have ${word} in it": }

After some research I found what I think was the issue.

Puppet Labs - The Puppet Language - Regular expressions cannot be converted to boolean values.

Luckily, puppetlabs/stdlib provides a clean way to work around that. Using the member function I split mylist into an array, and then test if word is part of that array.

$my_array = split($::my_list, ':')
if member($my_array, $word)
  notify { "${my_array} has ${word} in it":}
  notify { "${my_array} doesn't have ${word} in it":}