Hello all, I''ve been fighting a pesky regex issue and I was hoping somebody might have a solution handy. I''m trying to evaluate the hostname variable based on a few regex entries and apply some configurations accordingly. Here''s what I''ve got: if ($hostname == ''/^([a-z]*[-]\d{2,})*$/'') or ($hostname == ''/^([a-zA-Z0-9])*$/'') { another variant: if ($hostname == ''/^([a-z]*[-]\d{2,})*$/'') || ($hostname == ''/^([a-zA-Z0-9])*$/'') { I expect the second option to work as it seems - according to my reading - to be more "ruby friendly". Has anybody used this syntax successfully in the past? Additionally, I suspect I could be bastardizing this as I''m not familiar with ruby. Thanks in advance for the help. Cheers, Mike -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Sep 18, 2013, at 12:33 PM, Mike Reed <mjohn.reed@gmail.com> wrote:> Hello all, > > I''ve been fighting a pesky regex issue and I was hoping somebody might have a solution handy. I''m trying to evaluate the hostname variable based on a few regex entries and apply some configurations accordingly. > > Here''s what I''ve got: > > if ($hostname == ''/^([a-z]*[-]\d{2,})*$/'') or ($hostname == ''/^([a-zA-Z0-9])*$/'') { > > another variant: > > if ($hostname == ''/^([a-z]*[-]\d{2,})*$/'') || ($hostname == ''/^([a-zA-Z0-9])*$/'') { > > I expect the second option to work as it seems - according to my reading - to be more "ruby friendly". > > Has anybody used this syntax successfully in the past? Additionally, I suspect I could be bastardizing this as I''m not familiar with ruby. > > Thanks in advance for the help. > > Cheers, > > MikeSince you''re doing regex matching you need to use the ''=~'' operator instead of ''=='', like so: if ( $::hostname =~ /^foo/ ) or ( $::hostname =~ /^bar/ ) { -- Peter Bukowinski -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Thank you very much Peter. I also found that putting the regex entry in single quotes - as in my above examples - does not give me the expected results. As per your example, the regex entries are properly parsed when entries start and end with a forward slash. I hope this helps somebody else down the line. Cheers and thanks again. Mike On Wednesday, September 18, 2013 9:43:22 AM UTC-7, pmbuko wrote:> > On Sep 18, 2013, at 12:33 PM, Mike Reed <mjohn...@gmail.com <javascript:>> > wrote: > > > Hello all, > > > > I''ve been fighting a pesky regex issue and I was hoping somebody might > have a solution handy. I''m trying to evaluate the hostname variable based > on a few regex entries and apply some configurations accordingly. > > > > Here''s what I''ve got: > > > > if ($hostname == ''/^([a-z]*[-]\d{2,})*$/'') or ($hostname == > ''/^([a-zA-Z0-9])*$/'') { > > > > another variant: > > > > if ($hostname == ''/^([a-z]*[-]\d{2,})*$/'') || ($hostname == > ''/^([a-zA-Z0-9])*$/'') { > > > > I expect the second option to work as it seems - according to my reading > - to be more "ruby friendly". > > > > Has anybody used this syntax successfully in the past? Additionally, I > suspect I could be bastardizing this as I''m not familiar with ruby. > > > > Thanks in advance for the help. > > > > Cheers, > > > > Mike > > Since you''re doing regex matching you need to use the ''=~'' operator > instead of ''=='', like so: > > if ( $::hostname =~ /^foo/ ) or ( $::hostname =~ /^bar/ ) { > > -- > Peter Bukowinski-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.