2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>re - Perl pragma to alter regular expression behaviour
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> re - Perl pragma to alter regular expression behaviour
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
31 <h1><a name=
"name">NAME
</a></h1>
32 <p>re - Perl pragma to alter regular expression behaviour
</p>
36 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
39 ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here
</pre>
41 $pat = '(?{ $foo =
1 })';
43 /foo${pat}bar/; # won't fail (when not under -T switch)
</pre>
46 no re 'taint'; # the default
47 ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
</pre>
49 no re 'eval'; # the default
50 /foo${pat}bar/; # disallowed (with or without -T switch)
53 use re 'debug'; # NOT lexically scoped (as others are)
54 /^(.*)$/s; # output debugging info during
55 # compile and run time
</pre>
57 use re 'debugcolor'; # same as 'debug', but with colored output
59 <p>(We use $^X in these examples because it's tainted by default.)
</p>
63 <h1><a name=
"description">DESCRIPTION
</a></h1>
64 <p>When
<code>use re 'taint'
</code> is in effect, and a tainted string is the target
65 of a regex, the regex memories (or values returned by the m// operator
66 in list context) are tainted. This feature is useful when regex operations
67 on tainted data aren't meant to extract safe substrings, but to perform
68 other transformations.
</p>
69 <p>When
<code>use re 'eval'
</code> is in effect, a regex is allowed to contain
70 <code>(?{ ... })
</code> zero-width assertions even if regular expression contains
71 variable interpolation. That is normally disallowed, since it is a
72 potential security risk. Note that this pragma is ignored when the regular
73 expression is obtained from tainted data, i.e. evaluation is always
74 disallowed with tainted regular expressions. See
<a href=
"file://C|\msysgit\mingw\html/pod/perlre.html#___code___">(?{ code }) in the perlre manpage
</a>.
</p>
75 <p>For the purpose of this pragma, interpolation of precompiled regular
76 expressions (i.e., the result of
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_qr_"><code>qr//
</code></a>) is
<em>not
</em> considered variable
77 interpolation. Thus:
</p>
80 <p><em>is
</em> allowed if $pat is a precompiled regular expression, even
81 if $pat contains
<code>(?{ ... })
</code> assertions.
</p>
82 <p>When
<code>use re 'debug'
</code> is in effect, perl emits debugging messages when
83 compiling and using regular expressions. The output is the same as that
84 obtained by running a
<code>-DDEBUGGING
</code>-enabled perl interpreter with the
85 <strong>-Dr
</strong> switch. It may be quite voluminous depending on the complexity
86 of the match. Using
<code>debugcolor
</code> instead of
<code>debug
</code> enables a
87 form of output that can be used to get a colorful display on terminals
88 that understand termcap color sequences. Set
<code>$ENV{PERL_RE_TC}
</code> to a
89 comma-separated list of
<code>termcap
</code> properties to use for highlighting
90 strings on/off, pre-point part on/off.
91 See
<a href=
"file://C|\msysgit\mingw\html/pod/perldebug.html#debugging_regular_expressions">Debugging regular expressions in the perldebug manpage
</a> for additional info.
</p>
92 <p>The directive
<code>use re 'debug'
</code> is
<em>not lexically scoped
</em>, as the
93 other directives are. It has both compile-time and run-time effects.
</p>
94 <p>See
<a href=
"file://C|\msysgit\mingw\html/pod/perlmodlib.html#pragmatic_modules">Pragmatic Modules in the perlmodlib manpage
</a>.
</p>
95 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
96 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
97 <big><strong><span class=
"block"> re - Perl pragma to alter regular expression behaviour
</span></strong></big>