File: re.html

package info (click to toggle)
perl-doc-html 5.26.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 39,400 kB
  • sloc: xml: 36; makefile: 7
file content (809 lines) | stat: -rw-r--r-- 42,553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>re - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link rel="search" type="application/opensearchdescription+xml" title="Search perldoc.perl.org" href="/static/search.xml"/>
  <link href="static/css-20100830.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
  <link href="static/exploreperl.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
	<div id="strapline">
	  Perl Programming Documentation
	</div>
	<div id="download_link" class="download">
	  <a href="http://www.perl.org/get.html">Download Perl</a>
	</div>
	<div id="explore_link" class="download">
	  <a id="explore_anchor" href="#">Explore</a>
	</div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            
	    <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
            
	      <div class="side_panel doc_panel">
		<p>Tools</p>
		<ul>
		  <li><a href="preferences.html">Preferences</a>
		</ul>
	      </div>
            
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>re</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 26.0 documentation
              </div>
              <div class="page_links" id="page_links_top">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
              </div>
	      <div class="page_links" id="page_links_bottom">
		
                  <a href="#" id="page_index_toggle">Show page index</a> &bull;
		
                <a href="#" id="recent_pages_toggle">Show recent pages</a>		
	      </div>
	      <div id="search_form">
		<form action="search.html" method="GET" id="search">
		  <input type="text" name="q" id="search_box" alt="Search">
		</form>
	      </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-pragmas.html">Pragmas</a> &gt;
      
    
    re
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>

	    <div id="recent_pages" class="hud_container">
	      <div id="recent_pages_header" class="hud_header">
		<div id="recent_pages_close" class="hud_close"><a href="#" onClick="recentPages.hide();return false;"></a></div>
		<div id="recent_pages_title" class="hud_title"><span class="hud_span_top">Recently read</span></div>
		<div id="recent_pages_topright" class="hud_topright"></div>
	      </div>
	      <div id="recent_pages_content" class="hud_content">
	      </div>
	      <div id="recent_pages_footer" class="hud_footer">
		<div id="recent_pages_bottomleft" class="hud_bottomleft"></div>
		<div id="recent_pages_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
		<div id="recent_pages_resize" class="hud_resize"></div>
	      </div>
	    </div>
  
	    <div id="from_search"></div>
            <h1>re</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#'taint'-mode">'taint' mode</a><li><a href="#'eval'-mode">'eval' mode</a><li><a href="#'strict'-mode">'strict' mode</a><li><a href="#'%2fflags'-mode">'/flags' mode</a><li><a href="#'debug'-mode">'debug' mode</a><li><a href="#'Debug'-mode">'Debug' mode</a><li><a href="#Exportable-Functions">Exportable Functions</a></ul><li><a href="#SEE-ALSO">SEE ALSO</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>re - Perl pragma to alter regular expression behaviour</p>
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;taint&#39;</span><span class="sc">;</span></li><li>    <span class="s">(</span><span class="i">$x</span><span class="s">)</span> = <span class="s">(</span><span class="i">$^X</span> =~ <span class="q">/^(.*)$/s</span><span class="s">)</span><span class="sc">;</span>     <span class="c"># $x is tainted here</span></li><li></li><li>    <span class="i">$pat</span> = <span class="q">&#39;(?{ $foo = 1 })&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;eval&#39;</span><span class="sc">;</span></li><li>    <span class="q">/foo${pat}bar/</span><span class="sc">;</span>		   <span class="c"># won&#39;t fail (when not under -T</span></li><li>                                   <span class="c"># switch)</span></li><li></li><li>    <span class="s">{</span></li><li>	<a class="l_k" href="functions/no.html">no</a> <span class="w">re</span> <span class="q">&#39;taint&#39;</span><span class="sc">;</span>		   <span class="c"># the default</span></li><li>	<span class="s">(</span><span class="i">$x</span><span class="s">)</span> = <span class="s">(</span><span class="i">$^X</span> =~ <span class="q">/^(.*)$/s</span><span class="s">)</span><span class="sc">;</span> <span class="c"># $x is not tainted here</span></li><li></li><li>	<a class="l_k" href="functions/no.html">no</a> <span class="w">re</span> <span class="q">&#39;eval&#39;</span><span class="sc">;</span>		   <span class="c"># the default</span></li><li>	<span class="q">/foo${pat}bar/</span><span class="sc">;</span>		   <span class="c"># disallowed (with or without -T</span></li><li>                                   <span class="c"># switch)</span></li><li>    <span class="s">}</span></li><li></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;strict&#39;</span><span class="sc">;</span>               <span class="c"># Raise warnings for more conditions</span></li><li></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;/ix&#39;</span><span class="sc">;</span></li><li>    <span class="q">&quot;FOO&quot;</span> =~ <span class="q">/ foo /</span><span class="sc">;</span> <span class="c"># /ix implied</span></li><li>    <a class="l_k" href="functions/no.html">no</a> <span class="w">re</span> <span class="q">&#39;/x&#39;</span><span class="sc">;</span></li><li>    <span class="q">&quot;FOO&quot;</span> =~ <span class="q">/foo/</span><span class="sc">;</span> <span class="c"># just /i implied</span></li><li></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;debug&#39;</span><span class="sc">;</span>		   <span class="c"># output debugging info during</span></li><li>    <span class="q">/^(.*)$/s</span><span class="sc">;</span>			   <span class="c"># compile and run time</span></li><li></li><li></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;debugcolor&#39;</span><span class="sc">;</span>	   <span class="c"># same as &#39;debug&#39;, but with colored</span></li><li>                                   <span class="c"># output</span></li><li>    ...</li><li></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">qw(Debug All)</span><span class="sc">;</span>          <span class="c"># Same as &quot;use re &#39;debug&#39;&quot;, but you</span></li><li>                                   <span class="c"># can use &quot;Debug&quot; with things other</span></li><li>                                   <span class="c"># than &#39;All&#39;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">qw(Debug More)</span><span class="sc">;</span>         <span class="c"># &#39;All&#39; plus output more details</span></li><li>    <a class="l_k" href="functions/no.html">no</a> <span class="w">re</span> <span class="q">qw(Debug ALL)</span><span class="sc">;</span>           <span class="c"># Turn on (almost) all re debugging</span></li><li>                                   <span class="c"># in this scope</span></li><li></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">qw(is_regexp regexp_pattern)</span><span class="sc">;</span> <span class="c"># import utility functions</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$pat</span><span class="cm">,</span><span class="i">$mods</span><span class="s">)</span>=<span class="i">regexp_pattern</span><span class="s">(</span><span class="q">qr/foo/i</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><span class="i">is_regexp</span><span class="s">(</span><span class="i">$obj</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Got regexp: &quot;</span><span class="cm">,</span></li><li>            <a class="l_k" href="functions/scalar.html">scalar</a> <span class="i">regexp_pattern</span><span class="s">(</span><span class="i">$obj</span><span class="s">)</span><span class="sc">;</span> <span class="c"># just as perl would stringify</span></li><li>    <span class="s">}</span>                                    <span class="c"># it but no hassle with blessed</span></li><li>                                         <span class="c"># re&#39;s.</span></li></ol></pre><p>(We use $^X in these examples because it's tainted by default.)</p>
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<a name="'taint'-mode"></a><h2>'taint' mode</h2>
<p>When <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;taint&#39;</span></code>
 is in effect, and a tainted string is the target
of a regexp, the regexp memories (or values returned by the m// operator
in list context) are tainted.  This feature is useful when regexp operations
on tainted data aren't meant to extract safe substrings, but to perform
other transformations.</p>
<a name="'eval'-mode"></a><h2>'eval' mode</h2>
<p>When <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;eval&#39;</span></code>
 is in effect, a regexp is allowed to contain
<code class="inline">(?{ ... })</code> zero-width assertions and <code class="inline"><span class="s">(</span><span class="q">??</span><span class="s">{</span> ... <span class="s">}</span><span class="s">)</span></code>
 postponed
subexpressions that are derived from variable interpolation, rather than
appearing literally within the regexp.  That is normally disallowed, since
it is a
potential security risk.  Note that this pragma is ignored when the regular
expression is obtained from tainted data, i.e.  evaluation is always
disallowed with tainted regular expressions.  See <a href="perlre.html#(%3f%7b-code-%7d)">(?{ code }) in perlre</a> 
and <a href="perlre.html#(%3f%3f%7b-code-%7d)">(??{ code }) in perlre</a>.</p>
<p>For the purpose of this pragma, interpolation of precompiled regular
expressions (i.e., the result of <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code>) is <i>not</i> considered variable
interpolation.  Thus:</p>
<pre class="verbatim"><ol><li>    <span class="q">/foo${pat}bar/</span></li></ol></pre><p><i>is</i> allowed if $pat is a precompiled regular expression, even
if $pat contains <code class="inline">(?{ ... })</code> assertions or <code class="inline"><span class="s">(</span><span class="q">??</span><span class="s">{</span> ... <span class="s">}</span><span class="s">)</span></code>
 subexpressions.</p>
<a name="'strict'-mode"></a><h2>'strict' mode</h2>
<p>Note that this is an experimental feature which may be changed or removed in a
future Perl release.</p>
<p>When <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;strict&#39;</span></code>
 is in effect, stricter checks are applied than
otherwise when compiling regular expressions patterns.  These may cause more
warnings to be raised than otherwise, and more things to be fatal instead of
just warnings.  The purpose of this is to find and report at compile time some
things, which may be legal, but have a reasonable possibility of not being the
programmer's actual intent.  This automatically turns on the <code class="inline"><span class="q">&quot;regexp&quot;</span></code>

warnings category (if not already on) within its scope.</p>
<p>As an example of something that is caught under <code class="inline"><span class="q">&quot;strict&#39;</span></code>
, but not
otherwise, is the pattern</p>
<pre class="verbatim"><ol><li> <span class="q">qr/\xABC/</span></li></ol></pre><p>The <code class="inline"><span class="q">&quot;\x&quot;</span></code>
 construct without curly braces should be followed by exactly two
hex digits; this one is followed by three.  This currently evaluates as
equivalent to</p>
<pre class="verbatim"><ol><li> <span class="q">qr/\x{AB}C/</span></li></ol></pre><p>that is, the character whose code point value is <code class="inline"><span class="n">0xAB</span></code>
, followed by the
letter <code class="inline"><span class="w">C</span></code>
.  But since <code class="inline"><span class="w">C</span></code>
 is a a hex digit, there is a reasonable chance
that the intent was</p>
<pre class="verbatim"><ol><li> <span class="q">qr/\x{ABC}/</span></li></ol></pre><p>that is the single character at <code class="inline"><span class="n">0xABC</span></code>
.  Under <code class="inline"><span class="q">&#39;strict&#39;</span></code>
 it is an error to
not follow <code class="inline">\<span class="w">x</span></code>
 with exactly two hex digits.  When not under <code class="inline"><span class="q">&#39;strict&#39;</span></code>
 a
warning is generated if there is only one hex digit, and no warning is raised
if there are more than two.</p>
<p>It is expected that what exactly <code class="inline"><span class="q">&#39;strict&#39;</span></code>
 does will evolve over time as we
gain experience with it.  This means that programs that compile under it in
today's Perl may not compile, or may have more or fewer warnings, in future
Perls.  There is no backwards compatibility promises with regards to it.  Also
there are already proposals for an alternate syntax for enabling it.  For
these reasons, using it will raise a <code class="inline"><span class="w">experimental::re_strict</span></code>
 class warning,
unless that category is turned off.</p>
<p>Note that if a pattern compiled within <code class="inline"><span class="q">&#39;strict&#39;</span></code>
 is recompiled, say by
interpolating into another pattern, outside of <code class="inline"><span class="q">&#39;strict&#39;</span></code>
, it is not checked
again for strictness.  This is because if it works under strict it must work
under non-strict.</p>
<a name="'%2fflags'-mode"></a><h2>'/flags' mode</h2>
<p>When <code class="inline">use re '/<i>flags</i>'</code> is specified, the given <i>flags</i> are automatically
added to every regular expression till the end of the lexical scope.
<i>flags</i> can be any combination of
<code class="inline"><span class="q">&#39;a&#39;</span></code>
,
<code class="inline"><span class="q">&#39;aa&#39;</span></code>
,
<code class="inline"><span class="q">&#39;d&#39;</span></code>
,
<code class="inline"><span class="q">&#39;i&#39;</span></code>
,
<code class="inline"><span class="q">&#39;l&#39;</span></code>
,
<code class="inline"><span class="q">&#39;m&#39;</span></code>
,
<code class="inline"><span class="q">&#39;n&#39;</span></code>
,
<code class="inline"><span class="q">&#39;p&#39;</span></code>
,
<code class="inline"><span class="q">&#39;s&#39;</span></code>
,
<code class="inline"><span class="q">&#39;u&#39;</span></code>
,
<code class="inline"><span class="q">&#39;x&#39;</span></code>
,
and/or
<code class="inline"><span class="q">&#39;xx&#39;</span></code>
.</p>
<p><code class="inline">no re '/<i>flags</i>'</code> will turn off the effect of <code class="inline">use re '/<i>flags</i>'</code> for the
given flags.</p>
<p>For example, if you want all your regular expressions to have /msxx on by
default, simply put</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;/msxx&#39;</span><span class="sc">;</span></li></ol></pre><p>at the top of your code.</p>
<p>The character set <code class="inline"><span class="q">/adul</span></code>
 flags cancel each other out. So, in this example,</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&quot;/u&quot;</span><span class="sc">;</span></li><li>    <span class="q">&quot;ss&quot;</span> =~ <span class="q">/\xdf/</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&quot;/d&quot;</span><span class="sc">;</span></li><li>    <span class="q">&quot;ss&quot;</span> =~ <span class="q">/\xdf/</span><span class="sc">;</span></li></ol></pre><p>the second <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span></code>
 does an implicit <code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">re</span> <span class="q">&#39;/u&#39;</span></code>
.</p>
<p>Similarly,</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&quot;/xx&quot;</span><span class="sc">;</span>   <span class="c"># Doubled-x</span></li><li>    ...</li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&quot;/x&quot;</span><span class="sc">;</span>    <span class="c"># Single x from here on</span></li><li>    ...</li></ol></pre><p>Turning on one of the character set flags with <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span></code>
 takes precedence over the
<code class="inline"><span class="w">locale</span></code>
 pragma and the 'unicode_strings' <code class="inline"><span class="w">feature</span></code>
, for regular
expressions. Turning off one of these flags when it is active reverts to
the behaviour specified by whatever other pragmata are in scope. For
example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">feature</span> <span class="q">&quot;unicode_strings&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/no.html">no</a> <span class="w">re</span> <span class="q">&quot;/u&quot;</span><span class="sc">;</span> <span class="c"># does nothing</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&quot;/l&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/no.html">no</a> <span class="w">re</span> <span class="q">&quot;/l&quot;</span><span class="sc">;</span> <span class="c"># reverts to unicode_strings behaviour</span></li></ol></pre><a name="'debug'-mode"></a><h2>'debug' mode</h2>
<p>When <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;debug&#39;</span></code>
 is in effect, perl emits debugging messages when
compiling and using regular expressions.  The output is the same as that
obtained by running a <code class="inline">-<span class="w">DDEBUGGING</span></code>
-enabled perl interpreter with the
<b>-Dr</b> switch. It may be quite voluminous depending on the complexity
of the match.  Using <code class="inline"><span class="w">debugcolor</span></code>
 instead of <code class="inline"><span class="w">debug</span></code>
 enables a
form of output that can be used to get a colorful display on terminals
that understand termcap color sequences.  Set <code class="inline"><span class="i">$ENV</span>{<span class="w">PERL_RE_TC</span>}</code>
 to a
comma-separated list of <code class="inline"><span class="w">termcap</span></code>
 properties to use for highlighting
strings on/off, pre-point part on/off.
See <a href="perldebug.html#Debugging-Regular-Expressions">Debugging Regular Expressions in perldebug</a> for additional info.</p>
<p>As of 5.9.5 the directive <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;debug&#39;</span></code>
 and its equivalents are
lexically scoped, as the other directives are.  However they have both
compile-time and run-time effects.</p>
<p>See <a href="perlmodlib.html#Pragmatic-Modules">Pragmatic Modules in perlmodlib</a>.</p>
<a name="'Debug'-mode"></a><h2>'Debug' mode</h2>
<p>Similarly <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">'Debug'</span></code>
 produces debugging output, the difference
being that it allows the fine tuning of what debugging output will be
emitted. Options are divided into three groups, those related to
compilation, those related to execution and those related to special
purposes. The options are as follows:</p>
<ul>
<li><a name="Compile-related-options"></a><b>Compile related options</b>
<ul>
<li><a name="COMPILE"></a><b>COMPILE</b>
<p>Turns on all compile related debug options.</p>
</li>
<li><a name="PARSE"></a><b>PARSE</b>
<p>Turns on debug output related to the process of parsing the pattern.</p>
</li>
<li><a name="OPTIMISE"></a><b>OPTIMISE</b>
<p>Enables output related to the optimisation phase of compilation.</p>
</li>
<li><a name="TRIEC"></a><b>TRIEC</b>
<p>Detailed info about trie compilation.</p>
</li>
<li><a name="DUMP"></a><b>DUMP</b>
<p>Dump the final program out after it is compiled and optimised.</p>
</li>
<li><a name="FLAGS"></a><b>FLAGS</b>
<p>Dump the flags associated with the program</p>
</li>
<li><a name="TEST"></a><b>TEST</b>
<p>Print output intended for testing the internals of the compile process</p>
</li>
</ul>
</li>
<li><a name="Execute-related-options"></a><b>Execute related options</b>
<ul>
<li><a name="EXECUTE"></a><b>EXECUTE</b>
<p>Turns on all execute related debug options.</p>
</li>
<li><a name="MATCH"></a><b>MATCH</b>
<p>Turns on debugging of the main matching loop.</p>
</li>
<li><a name="TRIEE"></a><b>TRIEE</b>
<p>Extra debugging of how tries execute.</p>
</li>
<li><a name="INTUIT"></a><b>INTUIT</b>
<p>Enable debugging of start-point optimisations.</p>
</li>
</ul>
</li>
<li><a name="Extra-debugging-options"></a><b>Extra debugging options</b>
<ul>
<li><a name="EXTRA"></a><b>EXTRA</b>
<p>Turns on all "extra" debugging options.</p>
</li>
<li><a name="BUFFERS"></a><b>BUFFERS</b>
<p>Enable debugging the capture group storage during match. Warning,
this can potentially produce extremely large output.</p>
</li>
<li><a name="TRIEM"></a><b>TRIEM</b>
<p>Enable enhanced TRIE debugging. Enhances both TRIEE
and TRIEC.</p>
</li>
<li><a name="STATE"></a><b>STATE</b>
<p>Enable debugging of states in the engine.</p>
</li>
<li><a name="STACK"></a><b>STACK</b>
<p>Enable debugging of the recursion stack in the engine. Enabling
or disabling this option automatically does the same for debugging
states as well. This output from this can be quite large.</p>
</li>
<li><a name="GPOS"></a><b>GPOS</b>
<p>Enable debugging of the \G modifier.</p>
</li>
<li><a name="OPTIMISEM"></a><b>OPTIMISEM</b>
<p>Enable enhanced optimisation debugging and start-point optimisations.
Probably not useful except when debugging the regexp engine itself.</p>
</li>
<li><a name="OFFSETS"></a><b>OFFSETS</b>
<p>Dump offset information. This can be used to see how regops correlate
to the pattern. Output format is</p>
<pre class="verbatim"><ol><li>   <span class="j">NODENUM:</span><span class="w">POSITION</span><span class="s">[</span><span class="w">LENGTH</span><span class="s">]</span></li></ol></pre><p>Where 1 is the position of the first char in the string. Note that position
can be 0, or larger than the actual length of the pattern, likewise length
can be zero.</p>
</li>
<li><a name="OFFSETSDBG"></a><b>OFFSETSDBG</b>
<p>Enable debugging of offsets information. This emits copious
amounts of trace information and doesn't mesh well with other
debug options.</p>
<p>Almost definitely only useful to people hacking
on the offsets part of the debug engine.</p>
</li>
</ul>
</li>
<li><a name="Other-useful-flags"></a><b>Other useful flags</b>
<p>These are useful shortcuts to save on the typing.</p>
<ul>
<li><a name="ALL"></a><b>ALL</b>
<p>Enable all options at once except OFFSETS, OFFSETSDBG and BUFFERS.
(To get every single option without exception, use both ALL and EXTRA.)</p>
</li>
<li><a name="All"></a><b>All</b>
<p>Enable DUMP and all execute options. Equivalent to:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">'debug'</span><span class="sc">;</span></li></ol></pre></li>
<li><a name="MORE"></a><b>MORE</b>
</li>
<li><a name="More"></a><b>More</b>
<p>Enable the options enabled by "All", plus STATE, TRIEC, and TRIEM.</p>
</li>
</ul>
</li>
</ul>
<p>As of 5.9.5 the directive <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">re</span> <span class="q">&#39;debug&#39;</span></code>
 and its equivalents are
lexically scoped, as are the other directives.  However they have both
compile-time and run-time effects.</p>
<a name="Exportable-Functions"></a><h2>Exportable Functions</h2>
<p>As of perl 5.9.5 're' debug contains a number of utility functions that
may be optionally exported into the caller's namespace. They are listed
below.</p>
<ul>
<li><a name="is_regexp(%24ref)"></a><b>is_regexp($ref)</b>
<p>Returns true if the argument is a compiled regular expression as returned
by <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code>, false if it is not.</p>
<p>This function will not be confused by overloading or blessing. In
internals terms, this extracts the regexp pointer out of the
PERL_MAGIC_qr structure so it cannot be fooled.</p>
</li>
<li><a name="regexp_pattern(%24ref)"></a><b>regexp_pattern($ref)</b>
<p>If the argument is a compiled regular expression as returned by <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code>,
then this function returns the pattern.</p>
<p>In list context it returns a two element list, the first element
containing the pattern and the second containing the modifiers used when
the pattern was compiled.</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$pat</span><span class="cm">,</span> <span class="i">$mods</span><span class="s">)</span> = <span class="i">regexp_pattern</span><span class="s">(</span><span class="i">$ref</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>In scalar context it returns the same as perl would when stringifying a raw
<code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code> with the same pattern inside.  If the argument is not a compiled
reference then this routine returns false but defined in scalar context,
and the empty list in list context. Thus the following</p>
<pre class="verbatim"><ol><li>    if <span class="s">(</span><span class="i">regexp_pattern</span><span class="s">(</span><span class="i">$ref</span><span class="s">)</span> eq <span class="q">&#39;(?^i:foo)&#39;</span><span class="s">)</span></li></ol></pre><p>will be warning free regardless of what $ref actually is.</p>
<p>Like <code class="inline"><span class="w">is_regexp</span></code>
 this function will not be confused by overloading
or blessing of the object.</p>
</li>
<li><a name="regmust(%24ref)"></a><b>regmust($ref)</b>
<p>If the argument is a compiled regular expression as returned by <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code>,
then this function returns what the optimiser considers to be the longest
anchored fixed string and longest floating fixed string in the pattern.</p>
<p>A <i>fixed string</i> is defined as being a substring that must appear for the
pattern to match. An <i>anchored fixed string</i> is a fixed string that must
appear at a particular offset from the beginning of the match. A <i>floating
fixed string</i> is defined as a fixed string that can appear at any point in
a range of positions relative to the start of the match. For example,</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$qr</span> = <span class="q">qr/here .* there/x</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$anchored</span><span class="cm">,</span> <span class="i">$floating</span><span class="s">)</span> = <span class="i">regmust</span><span class="s">(</span><span class="i">$qr</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;anchored:'$anchored'\nfloating:'$floating'\n&quot;</span><span class="sc">;</span></li></ol></pre><p>results in</p>
<pre class="verbatim"><ol><li>    anchored:'here'</li><li>    floating:'there'</li></ol></pre><p>Because the <code class="inline"><span class="w">here</span></code>
 is before the <code class="inline">.*</code> in the pattern, its position
can be determined exactly. That's not true, however, for the <code class="inline"><span class="w">there</span></code>
;
it could appear at any point after where the anchored string appeared.
Perl uses both for its optimisations, preferring the longer, or, if they are
equal, the floating.</p>
<p><b>NOTE:</b> This may not necessarily be the definitive longest anchored and
floating string. This will be what the optimiser of the Perl that you
are using thinks is the longest. If you believe that the result is wrong
please report it via the <a href="perlbug.html">perlbug</a> utility.</p>
</li>
<li><a name="regname(%24name%2c%24all)"></a><b>regname($name,$all)</b>
<p>Returns the contents of a named buffer of the last successful match. If
$all is true, then returns an array ref containing one entry per buffer,
otherwise returns the first defined buffer.</p>
</li>
<li><a name="regnames(%24all)"></a><b>regnames($all)</b>
<p>Returns a list of all of the named buffers defined in the last successful
match. If $all is true, then it returns all names defined, if not it returns
only names which were involved in the match.</p>
</li>
<li><a name="regnames_count()"></a><b>regnames_count()</b>
<p>Returns the number of distinct names defined in the pattern used
for the last successful match.</p>
<p><b>Note:</b> this result is always the actual number of distinct
named buffers defined, it may not actually match that which is
returned by <code class="inline"><span class="i">regnames</span><span class="s">(</span><span class="s">)</span></code>
 and related routines when those routines
have not been called with the $all parameter set.</p>
</li>
</ul>
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
<p><a href="perlmodlib.html#Pragmatic-Modules">Pragmatic Modules in perlmodlib</a>.</p>




  <div id="page_index" class="hud_container">
    <div id="page_index_header" class="hud_header">
      <div id="page_index_close" class="hud_close"><a href="#" onClick="pageIndex.hide();return false;"></a></div>
      <div id="page_index_title" class="hud_title"><span class="hud_span_top">Page index</span></div>
      <div id="page_index_topright" class="hud_topright"></div>
    </div>
    <div id="page_index_content" class="hud_content">
      <ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#'taint'-mode">'taint' mode</a><li><a href="#'eval'-mode">'eval' mode</a><li><a href="#'strict'-mode">'strict' mode</a><li><a href="#'%2fflags'-mode">'/flags' mode</a><li><a href="#'debug'-mode">'debug' mode</a><li><a href="#'Debug'-mode">'Debug' mode</a><li><a href="#Exportable-Functions">Exportable Functions</a></ul><li><a href="#SEE-ALSO">SEE ALSO</a></ul>
    </div>
    <div id="page_index_footer" class="hud_footer">
      <div id="page_index_bottomleft" class="hud_bottomleft"></div>
      <div id="page_index_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
      <div id="page_index_resize" class="hud_resize"></div>
    </div>
  </div>


	    &nbsp;
          </div>
          <div id="content_footer">
          </div>
        </div>
        <div class="clear"></div>
      </div>
      
    <div id="footer">
      <div id="footer_content">
        <div id="footer_strapline">
          perldoc.perl.org - Official documentation for the Perl programming language
        </div>
        <div id="footer_links">
          <div id="address">
            <p class="name">Contact details</p>
            <p class="address">
	      Site maintained by <a href="mailto:jj@jonallen.info">Jon Allen (JJ)</a><br>
	    </p>
            <p class="contact">
              Documentation maintained by the <a href="http://lists.cpan.org/showlist.cgi?name=perl5-porters">Perl 5 Porters</a>
            </p>
          </div>
          <ul class="f1">
            <li>Manual
              <ul class="f2">
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">Changes</a>
              </ul>
            <li>Reference
              <ul class="f2">
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Variables</a>
              </ul>
            <li>Modules
              <ul class="f2">
                <li><a href="index-modules-A.html">Modules</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
              </ul>
            <li>Misc
              <ul class="f2">
                <li><a href="index-licence.html">License</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platforms</a>
              </ul>          </ul>
          <div class="clear"></div>
        </div>
      </div>
      <div id="footer_end">
      </div>
    </div>
      
    </div>
      <script language="JavaScript" type="text/javascript" src="static/exploreperl.js"></script>
      <script language="JavaScript" src="static/combined-20100403.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  perldoc.setPath(0);
  perldoc.pageName    = 're';
  perldoc.pageAddress = 're.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>