So Puppet DSL is ruby like then.... Think thats where I was going wrong. I went to the ruby page
Craig & Robert thanks. Alex On Friday, 5 August 2016 00:50:54 UTC+10, R.I. Pienaar wrote: > > > > ----- Original Message ----- > > From: "Robert Poulson" <robp...@gmail.com <javascript:>> > > To: "puppet-users" <puppet...@googlegroups.com <javascript:>> > > Sent: Thursday, 4 August, 2016 16:42:21 > > Subject: Re: [Puppet Users] Re: Puppet .... ruby regex > > >> > >> $pp_shortcertname= "${trusted['certname']}".match(/([^.]+)\./)[1] > >> > >> not sure I fully understand why this works and [] doesn't. > >> > >> Not 100% sure I understand what the [1] does ! > >> > > > > The parentheses are for capturing the matching text, and \1 for re-using > it > > as a backreference; [1] outside of the pattern. > > > > See > http://ruby-doc.org/core-2.1.1/Regexp.html#class-Regexp-label-Capturing > > this is not a ruby question, the code in question is PUPPET DSL. > > The DSL match function looks for a regex and returns what it finds and any > capture groups. > > You access the 2nd item in the array as array[1] > > if certname if hostname.domain.name > > $matches = $trusted["certname"].match(/([^.]+)\./) > > Here $matches will have ["hostname.", "hostname"] > > and $matches[1] will fetch "hostname" > > https://docs.puppet.com/puppet/latest/reference/function.html#match > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/59508afd-d498-4f8c-8fa6-36bc4acdc9e6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.