1re(3pm) Perl Programmers Reference Guide re(3pm)
2
3
4
6 re - Perl pragma to alter regular expression behaviour
7
9 use re 'taint';
10 ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here
11
12 $pat = '(?{ $foo = 1 })';
13 use re 'eval';
14 /foo${pat}bar/; # won't fail (when not under -T switch)
15
16 {
17 no re 'taint'; # the default
18 ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
19
20 no re 'eval'; # the default
21 /foo${pat}bar/; # disallowed (with or without -T switch)
22 }
23
24 use re 'debug'; # NOT lexically scoped (as others are)
25 /^(.*)$/s; # output debugging info during
26 # compile and run time
27
28 use re 'debugcolor'; # same as 'debug', but with colored output
29 ...
30
31 (We use $^X in these examples because it's tainted by default.)
32
34 When "use re 'taint'" is in effect, and a tainted string is the target
35 of a regex, the regex memories (or values returned by the m// operator
36 in list context) are tainted. This feature is useful when regex opera‐
37 tions on tainted data aren't meant to extract safe substrings, but to
38 perform other transformations.
39
40 When "use re 'eval'" is in effect, a regex is allowed to contain "(?{
41 ... })" zero-width assertions even if regular expression contains vari‐
42 able interpolation. That is normally disallowed, since it is a poten‐
43 tial security risk. Note that this pragma is ignored when the regular
44 expression is obtained from tainted data, i.e. evaluation is always
45 disallowed with tainted regular expressions. See "(?{ code })" in
46 perlre.
47
48 For the purpose of this pragma, interpolation of precompiled regular
49 expressions (i.e., the result of "qr//") is not considered variable
50 interpolation. Thus:
51
52 /foo${pat}bar/
53
54 is allowed if $pat is a precompiled regular expression, even if $pat
55 contains "(?{ ... })" assertions.
56
57 When "use re 'debug'" is in effect, perl emits debugging messages when
58 compiling and using regular expressions. The output is the same as
59 that obtained by running a "-DDEBUGGING"-enabled perl interpreter with
60 the -Dr switch. It may be quite voluminous depending on the complexity
61 of the match. Using "debugcolor" instead of "debug" enables a form of
62 output that can be used to get a colorful display on terminals that
63 understand termcap color sequences. Set $ENV{PERL_RE_TC} to a comma-
64 separated list of "termcap" properties to use for highlighting strings
65 on/off, pre-point part on/off. See "Debugging regular expressions" in
66 perldebug for additional info.
67
68 The directive "use re 'debug'" is not lexically scoped, as the other
69 directives are. It has both compile-time and run-time effects.
70
71 See "Pragmatic Modules" in perlmodlib.
72
73
74
75perl v5.8.8 2001-09-21 re(3pm)