Re: [Puppet Users] regsubst and regex
Ok, I totally forget that replacement part is not a search :D On Mon, Apr 16, 2012 at 5:00 PM, Thomas Bellman wrote: > On 2012-04-16 15:57, Antidot SAS top-posted: > > > Thx for the reply it helps. > > > > But how come the \2 returns something that I never asked? > > It doesn't. But since there are no occurrances of '^(.*)->(.*)', > then there are none that get replaced. Similarly, if you do: > >regsubst('foobar', 'x', 'y') > > you will get 'foobar', since there *is* no 'x' in 'foobar' that > can be replaced by a 'y'. > > >/Bellman > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] regsubst and regex
On 2012-04-16 15:57, Antidot SAS top-posted: > Thx for the reply it helps. > > But how come the \2 returns something that I never asked? It doesn't. But since there are no occurrances of '^(.*)->(.*)', then there are none that get replaced. Similarly, if you do: regsubst('foobar', 'x', 'y') you will get 'foobar', since there *is* no 'x' in 'foobar' that can be replaced by a 'y'. /Bellman -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] regsubst and regex
Thx for the reply it helps. But how come the \2 returns something that I never asked? On Mon, Apr 16, 2012 at 3:47 PM, Thomas Bellman wrote: > On 2012-04-16 15:26, Antidot SAS wrote: > > > A quick question for you, here is the code: > > $tt=regsubst("test","^(.*)->(.*)",'\2') > > > > Doesn't return: undef or nil, it does return: "test" > > As expected and intended. > > > Niether does $tt=regsubst("test","^(.?)->(.*)",'\2') > > or $tt=regsubst("test","^(.+?)->(.*)",'\2'). > > > > Is there a way to return undef if the string doesn't include > '->something' ? > > Perhaps something like this: > >$x = 'test' >$temp = regsubst($x, '^(.*)->(.*)', '\2') >if $temp == $x { ># No substitution done, must mean there is no "->" in $x >$tt = undef >} else { >$tt = $temp >} > > Or perhaps this: > >$tt = regsubst($x, '^(.*)->(.*)|.*', '\2') > > It will however give you the empty string (""), not undef, if there is > no "->" in the string. > > >/Bellman > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] regsubst and regex
On 2012-04-16 15:26, Antidot SAS wrote: > A quick question for you, here is the code: > $tt=regsubst("test","^(.*)->(.*)",'\2') > > Doesn't return: undef or nil, it does return: "test" As expected and intended. > Niether does $tt=regsubst("test","^(.?)->(.*)",'\2') > or $tt=regsubst("test","^(.+?)->(.*)",'\2'). > > Is there a way to return undef if the string doesn't include '->something' ? Perhaps something like this: $x = 'test' $temp = regsubst($x, '^(.*)->(.*)', '\2') if $temp == $x { # No substitution done, must mean there is no "->" in $x $tt = undef } else { $tt = $temp } Or perhaps this: $tt = regsubst($x, '^(.*)->(.*)|.*', '\2') It will however give you the empty string (""), not undef, if there is no "->" in the string. /Bellman -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
[Puppet Users] regsubst and regex
Hi everyone, A quick question for you, here is the code: $tt=regsubst("test","^(.*)->(.*)",'\2') Doesn't return: undef or nil, it does return: "test" Niether does $tt=regsubst("test","^(.?)->(.*)",'\2') or $tt=regsubst("test","^(.+?)->(.*)",'\2'). Is there a way to return undef if the string doesn't include '->something' ? Regards, JM -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.