4 module Puppet::Parser::Functions
5 newfunction(:grep, :type => :rvalue, :doc => <<-DOC
7 This function searches through an array and returns any elements that match
8 the provided regular expression.
11 array of elements that match the provided regular expression.
12 @example Example Usage:
13 grep(['aaa','bbb','ccc','aaaddd'], 'aaa') # Returns ['aaa','aaaddd']
15 > **Note:** that since Puppet 4.0.0, the built-in
16 [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function does
17 the "same" - as any logic can be used to filter, as opposed to just regular expressions:
18 ```['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' }```
22 if arguments.size != 2
23 raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2")
27 pattern = Regexp.new(arguments[1])
33 # vim: set ts=2 sw=2 et :