Sha256: a70cde5ccf17d85d7f8e269f33711a343c93650f104983ae9bbc07f78d076111

Contents?: true

Size: 1.35 KB

Versions: 57

Compression:

Stored size: 1.35 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|
  function_fail(["match() is only available when parser/evaluator future is in effect"])
end

Version data entries

57 entries across 57 versions & 2 rubygems

Version Path
puppet-retrospec-1.5.0 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-retrospec-1.4.1 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-retrospec-1.4.0 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-retrospec-1.3.2 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-retrospec-1.3.1 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-retrospec-1.3.0 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-4.7.1 lib/puppet/parser/functions/match.rb
puppet-4.7.1-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.7.1-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.7.1-universal-darwin lib/puppet/parser/functions/match.rb
puppet-retrospec-1.2.1 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-retrospec-1.2.0 vendor/gems/puppet-4.5.2/lib/puppet/parser/functions/match.rb
puppet-4.7.0 lib/puppet/parser/functions/match.rb
puppet-4.7.0-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.7.0-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.7.0-universal-darwin lib/puppet/parser/functions/match.rb
puppet-4.6.2 lib/puppet/parser/functions/match.rb
puppet-4.6.2-x86-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.6.2-x64-mingw32 lib/puppet/parser/functions/match.rb
puppet-4.6.2-universal-darwin lib/puppet/parser/functions/match.rb