Syntax
Regular expressions are written as patterns enclosed within forward slashes. Unlike in Ruby, you cannot specify options or encodings after the final
slash, like /node
.*/m.
if $host =~ /^www(\d+)\./ {
notify { "Welcome web server #$1": }
}Puppet uses Ruby’s standard regular expression
implementation to match patterns. Other forms of regular expression quoting,
like Ruby’s %r{^www(\d+)\.}, are not allowed. You cannot interpolate variables or
expressions into regex values.
If you are matching against a string that contains newlines, use \A and
\z instead of ^ and $, which match the
beginning and end of a line. This is a common mistake that can cause your regexp to
unintentionally match multiline text.
Some places in the language accept both real regex values and stringified regexes — that is, the same pattern quoted as a string instead of surrounded by slashes.