Sha256: 5f769bde2ea8b6faa4e68d6fc52b878bac09d8c5e931e4f5e7f9a7513e7ac580

Contents?: true

Size: 1.29 KB

Versions: 48

Compression:

Stored size: 1.29 KB

Contents

Puppet::Parser::Functions::newfunction(
  :match,
  :arity => 2,
  :doc => <<-DOC
Matches a regular expression against a string and returns an array containing the match
and any matched capturing groups.

The first argument is a string or array of strings. The second argument is either a
regular expression, regular expression represented as a string, or Regex or Pattern
data type that the function matches against the first argument.

The returned array contains the entire match at index 0, and each captured group at
subsequent index values. If the value or expression being matched is an array, the
function returns an array with mapped match results.

If the function doesn't find a match, it returns 'undef'.

**Example**: Matching a regular expression in a string

~~~ ruby
$matches = "abc123".match(/[a-z]+[1-9]+/)
# $matches contains [abc123]
~~~

**Example**: Matching a regular expressions with grouping captures in a string

~~~ ruby
$matches = "abc123".match(/([a-z]+)([1-9]+)/)
# $matches contains [abc123, abc, 123]
~~~

**Example**: Matching a regular expression with grouping captures in an array of strings

~~~ ruby
$matches = ["abc123","def456"].match(/([a-z]+)([1-9]+)/)
# $matches contains [[abc123, abc, 123], [def456, def, 456]]
~~~

- Since 4.0.0
DOC
) do |args|
  Error.is4x('match')
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
puppet-5.0.0 lib/puppet/parser/functions/match.rb
puppet-5.0.0-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-5.0.0-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-5.0.0-universal-darwin lib/puppet/parser/functions/match.rb
puppet-4.10.4 lib/puppet/parser/functions/match.rb
puppet-4.10.4-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.10.4-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.10.4-universal-darwin lib/puppet/parser/functions/match.rb
puppet-4.10.1 lib/puppet/parser/functions/match.rb
puppet-4.10.1-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.10.1-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.10.1-universal-darwin lib/puppet/parser/functions/match.rb
puppet-4.10.0 lib/puppet/parser/functions/match.rb
puppet-4.10.0-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.10.0-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.10.0-universal-darwin lib/puppet/parser/functions/match.rb
puppet-4.9.4 lib/puppet/parser/functions/match.rb
puppet-4.9.4-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.9.4-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.9.4-universal-darwin lib/puppet/parser/functions/match.rb