File: perlreapi.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 (1080 lines) | stat: -rw-r--r-- 87,077 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
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>perlreapi - 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>perlreapi</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-internals.html">Internals and C language interface</a> &gt;
      
    
    perlreapi
  

            </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>perlreapi</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#Callbacks">Callbacks</a><ul><li><a href="#comp">comp</a><li><a href="#exec">exec</a><li><a href="#intuit">intuit</a><li><a href="#checkstr">checkstr</a><li><a href="#free">free</a><li><a href="#Numbered-capture-callbacks">Numbered capture callbacks</a><li><a href="#Named-capture-callbacks">Named capture callbacks</a><li><a href="#qr_package">qr_package</a><li><a href="#dupe">dupe</a><li><a href="#op_comp">op_comp</a></ul><li><a href="#The-REGEXP-structure">The REGEXP structure</a><ul><li><a href="#engine">engine</a><li><a href="#mother_re">mother_re</a><li><a href="#extflags">extflags</a><li><a href="#minlen-minlenret">minlen minlenret</a><li><a href="#gofs">gofs</a><li><a href="#substrs">substrs</a><li><a href="#nparens%2c-lastparen%2c-and-lastcloseparen">nparens, lastparen, and lastcloseparen</a><li><a href="#intflags">intflags</a><li><a href="#pprivate">pprivate</a><li><a href="#swap">swap</a><li><a href="#offs">offs</a><li><a href="#precomp-prelen">precomp prelen</a><li><a href="#paren_names">paren_names</a><li><a href="#substrs">substrs</a><li><a href="#subbeg-sublen-saved_copy-suboffset-subcoffset">subbeg sublen saved_copy suboffset subcoffset</a><li><a href="#wrapped-wraplen">wrapped wraplen</a><li><a href="#seen_evals">seen_evals</a><li><a href="#refcnt">refcnt</a></ul><li><a href="#HISTORY">HISTORY</a><li><a href="#AUTHORS">AUTHORS</a><li><a href="#LICENSE">LICENSE</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>perlreapi - Perl regular expression plugin interface</p>
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>As of Perl 5.9.5 there is a new interface for plugging and using
regular expression engines other than the default one.</p>
<p>Each engine is supposed to provide access to a constant structure of the
following format:</p>
<pre class="verbatim"><ol><li>    <span class="w">typedef</span> <span class="w">struct</span> <span class="i">regexp_engine</span> <span class="s">{</span></li><li>        <span class="w">REGEXP</span>* <span class="s">(</span><span class="i">*comp</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                         <span class="w">const</span> <span class="w">SV</span> * <span class="w">const</span> <span class="w">pattern</span><span class="cm">,</span> <span class="w">const</span> <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">I32</span>     <span class="s">(</span><span class="i">*exec</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                         <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                         <span class="w">char</span>* <span class="w">stringarg</span><span class="cm">,</span></li><li>                         <span class="w">char</span>* <span class="w">strend</span><span class="cm">,</span> <span class="w">char</span>* <span class="w">strbeg</span><span class="cm">,</span></li><li>                         <span class="w">SSize_t</span> <span class="w">minend</span><span class="cm">,</span> <span class="w">SV</span>* <span class="w">sv</span><span class="cm">,</span></li><li>                         <span class="w">void</span>* <span class="w">data</span><span class="cm">,</span> <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">char</span>*   <span class="s">(</span><span class="i">*intuit</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                           <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span> <span class="w">SV</span> *<span class="w">sv</span><span class="cm">,</span></li><li>			   <span class="w">const</span> <span class="w">char</span> * <span class="w">const</span> <span class="w">strbeg</span><span class="cm">,</span></li><li>                           <span class="w">char</span> *<span class="w">strpos</span><span class="cm">,</span> <span class="w">char</span> *<span class="w">strend</span><span class="cm">,</span> <span class="w">U32</span> <span class="w">flags</span><span class="cm">,</span></li><li>                           <span class="w">struct</span> <span class="w">re_scream_pos_data_s</span> *<span class="w">data</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">SV</span>*     <span class="s">(</span><span class="i">*checkstr</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">void</span>    <span class="s">(</span><span class="i">*free</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">void</span>    <span class="s">(</span><span class="i">*numbered_buff_FETCH</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                                        <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                                        <span class="w">const</span> <span class="w">I32</span> <span class="w">paren</span><span class="cm">,</span></li><li>                                        <span class="w">SV</span> * <span class="w">const</span> <span class="w">sv</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">void</span>    <span class="s">(</span><span class="i">*numbered_buff_STORE</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                                        <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                                        <span class="w">const</span> <span class="w">I32</span> <span class="w">paren</span><span class="cm">,</span></li><li>                                        <span class="w">SV</span> <span class="w">const</span> * <span class="w">const</span> <span class="w">value</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">I32</span>     <span class="s">(</span><span class="i">*numbered_buff_LENGTH</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                                         <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                                         <span class="w">const</span> <span class="w">SV</span> * <span class="w">const</span> <span class="w">sv</span><span class="cm">,</span></li><li>                                         <span class="w">const</span> <span class="w">I32</span> <span class="w">paren</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">SV</span>*     <span class="s">(</span><span class="i">*named_buff</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                               <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                               <span class="w">SV</span> * <span class="w">const</span> <span class="w">key</span><span class="cm">,</span></li><li>                               <span class="w">SV</span> * <span class="w">const</span> <span class="w">value</span><span class="cm">,</span></li><li>                               <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">SV</span>*     <span class="s">(</span><span class="i">*named_buff_iter</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                                    <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                                    <span class="w">const</span> <span class="w">SV</span> * <span class="w">const</span> <span class="w">lastkey</span><span class="cm">,</span></li><li>                                    <span class="w">const</span> <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">SV</span>*     <span class="s">(</span><span class="i">*qr_package</span><span class="s">)</span><span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="c">#ifdef USE_ITHREADS</span></li><li>        <span class="w">void</span>*   <span class="s">(</span><span class="i">*dupe</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span> <span class="w">CLONE_PARAMS</span> *<span class="w">param</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="c">#endif</span></li><li>        <span class="w">REGEXP</span>* <span class="s">(</span><span class="i">*op_comp</span><span class="s">)</span> <span class="s">(</span>...<span class="s">)</span><span class="sc">;</span></li></ol></pre><p>When a regexp is compiled, its <code class="inline"><span class="w">engine</span></code>
 field is then set to point at
the appropriate structure, so that when it needs to be used Perl can find
the right routines to do so.</p>
<p>In order to install a new regexp handler, <code class="inline"><span class="i">$^H</span>{<span class="w">regcomp</span>}</code>
 is set
to an integer which (when casted appropriately) resolves to one of these
structures.  When compiling, the <code class="inline"><span class="w">comp</span></code>
 method is executed, and the
resulting <code class="inline"><span class="w">regexp</span></code>
 structure's engine field is expected to point back at
the same structure.</p>
<p>The pTHX_ symbol in the definition is a macro used by Perl under threading
to provide an extra argument to the routine holding a pointer back to
the interpreter that is executing the regexp. So under threading all
routines get an extra argument.</p>
<a name="Callbacks"></a><h1>Callbacks</h1>
<a name="comp"></a><h2>comp</h2>
<pre class="verbatim"><ol><li>    <span class="w">REGEXP</span>* <span class="i">comp</span><span class="s">(</span><span class="w">pTHX_</span> <span class="w">const</span> <span class="w">SV</span> * <span class="w">const</span> <span class="w">pattern</span><span class="cm">,</span> <span class="w">const</span> <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Compile the pattern stored in <code class="inline"><span class="w">pattern</span></code>
 using the given <code class="inline"><span class="w">flags</span></code>
 and
return a pointer to a prepared <code class="inline"><span class="w">REGEXP</span></code>
 structure that can perform
the match.  See <a href="#The-REGEXP-structure">The REGEXP structure</a> below for an explanation of
the individual fields in the REGEXP struct.</p>
<p>The <code class="inline"><span class="w">pattern</span></code>
 parameter is the scalar that was used as the
pattern.  Previous versions of Perl would pass two <code class="inline"><span class="w">char</span>*</code>
 indicating
the start and end of the stringified pattern; the following snippet can
be used to get the old parameters:</p>
<pre class="verbatim"><ol><li>    <span class="w">STRLEN</span> <span class="w">plen</span><span class="sc">;</span></li><li>    <span class="w">char</span>*  <a class="l_k" href="functions/exp.html">exp</a> = <span class="i">SvPV</span><span class="s">(</span><span class="w">pattern</span><span class="cm">,</span> <span class="w">plen</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="w">char</span>* <span class="w">xend</span> = <a class="l_k" href="functions/exp.html">exp</a> + <span class="w">plen</span><span class="sc">;</span></li></ol></pre><p>Since any scalar can be passed as a pattern, it's possible to implement
an engine that does something with an array (<code class="inline"><span class="q">&quot;ook&quot;</span> =~ <span class="s">[</span> <span class="q">qw/ eek</span>
<span class="q">hlagh /</span> <span class="s">]</span></code>
) or with the non-stringified form of a compiled regular
expression (<code class="inline"><span class="q">&quot;ook&quot;</span> =~ <span class="q">qr/eek/</span></code>
).  Perl's own engine will always
stringify everything using the snippet above, but that doesn't mean
other engines have to.</p>
<p>The <code class="inline"><span class="w">flags</span></code>
 parameter is a bitfield which indicates which of the
<code class="inline"><span class="w">msixpn</span></code>
 flags the regex was compiled with.  It also contains
additional info, such as if <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">locale</span></code>
 is in effect.</p>
<p>The <code class="inline"><span class="w">eogc</span></code>
 flags are stripped out before being passed to the comp
routine.  The regex engine does not need to know if any of these
are set, as those flags should only affect what Perl does with the
pattern and its match variables, not how it gets compiled and
executed.</p>
<p>By the time the comp callback is called, some of these flags have
already had effect (noted below where applicable).  However most of
their effect occurs after the comp callback has run, in routines that
read the <code class="inline"><span class="w">rx</span><span class="w">-&gt;extflags</span></code>
 field which it populates.</p>
<p>In general the flags should be preserved in <code class="inline"><span class="w">rx</span><span class="w">-&gt;extflags</span></code>
 after
compilation, although the regex engine might want to add or delete
some of them to invoke or disable some special behavior in Perl.  The
flags along with any special behavior they cause are documented below:</p>
<p>The pattern modifiers:</p>
<ul>
<li><a name="%2fm---RXf_PMf_MULTILINE"></a><b><code class="inline">/m</code> - RXf_PMf_MULTILINE</b>
<p>If this is in <code class="inline"><span class="w">rx</span><span class="w">-&gt;extflags</span></code>
 it will be passed to
<code class="inline"><span class="w">Perl_fbm_instr</span></code>
 by <code class="inline"><span class="w">pp_split</span></code>
 which will treat the subject string
as a multi-line string.</p>
</li>
<li><a name="%2fs---RXf_PMf_SINGLELINE"></a><b><code class="inline">/s</code> - RXf_PMf_SINGLELINE</b>
</li>
<li><a name="%2fi---RXf_PMf_FOLD"></a><b><code class="inline">/i</code> - RXf_PMf_FOLD</b>
</li>
<li><a name="%2fx---RXf_PMf_EXTENDED"></a><b><code class="inline">/x</code> - RXf_PMf_EXTENDED</b>
<p>If present on a regex, <code class="inline"><span class="q">&quot;#&quot;</span></code>
 comments will be handled differently by the
tokenizer in some cases.</p>
<p>TODO: Document those cases.</p>
</li>
<li><a name="%2fp---RXf_PMf_KEEPCOPY"></a><b><code class="inline">/p</code> - RXf_PMf_KEEPCOPY</b>
<p>TODO: Document this</p>
</li>
<li><a name="Character-set"></a><b>Character set</b>
<p>The character set rules are determined by an enum that is contained
in this field.  This is still experimental and subject to change, but
the current interface returns the rules by use of the in-line function
<code class="inline"><span class="i">get_regex_charset</span><span class="s">(</span><span class="w">const</span> <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span></code>
.  The only currently documented
value returned from it is REGEX_LOCALE_CHARSET, which is set if
<code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">locale</span></code>
 is in effect. If present in <code class="inline"><span class="w">rx</span><span class="w">-&gt;extflags</span></code>
,
<code class="inline"><a class="l_k" href="functions/split.html">split</a></code> will use the locale dependent definition of whitespace
when RXf_SKIPWHITE or RXf_WHITE is in effect.  ASCII whitespace
is defined as per <a href="perlapi.html#isSPACE">isSPACE</a>, and by the internal
macros <code class="inline"><span class="w">is_utf8_space</span></code>
 under UTF-8, and <code class="inline"><span class="w">isSPACE_LC</span></code>
 under <code class="inline"><a class="l_k" href="functions/use.html">use</a>
<span class="w">locale</span></code>
.</p>
</li>
</ul>
<p>Additional flags:</p>
<ul>
<li><a name="RXf_SPLIT"></a><b>RXf_SPLIT</b>
<p>This flag was removed in perl 5.18.0.  <code class="inline"><a class="l_k" href="functions/split.html">split</a> <span class="q">&#39; &#39;</span></code>
 is now special-cased
solely in the parser.  RXf_SPLIT is still #defined, so you can test for it.
This is how it used to work:</p>
<p>If <code class="inline"><a class="l_k" href="functions/split.html">split</a></code> is invoked as <code class="inline"><a class="l_k" href="functions/split.html">split</a> <span class="q">&#39; &#39;</span></code>
 or with no arguments (which
really means <code class="inline"><a class="l_k" href="functions/split.html">split</a><span class="s">(</span><span class="q">&#39; &#39;</span><span class="cm">,</span> <span class="i">$_</span><span class="s">)</span></code>
, see <a href="functions/split.html">split</a>), Perl will
set this flag.  The regex engine can then check for it and set the
SKIPWHITE and WHITE extflags.  To do this, the Perl engine does:</p>
<pre class="verbatim"><ol><li>    if (flags &amp; RXf_SPLIT &amp;&amp; r-&gt;prelen == 1 &amp;&amp; r-&gt;precomp[0] == ' ')</li><li>        r-&gt;extflags |= (RXf_SKIPWHITE|RXf_WHITE);</li></ol></pre></li>
</ul>
<p>These flags can be set during compilation to enable optimizations in
the <code class="inline"><a class="l_k" href="functions/split.html">split</a></code> operator.</p>
<ul>
<li><a name="RXf_SKIPWHITE"></a><b>RXf_SKIPWHITE</b>
<p>This flag was removed in perl 5.18.0.  It is still #defined, so you can
set it, but doing so will have no effect.  This is how it used to work:</p>
<p>If the flag is present in <code class="inline"><span class="w">rx</span><span class="w">-&gt;extflags</span></code>
 <code class="inline"><a class="l_k" href="functions/split.html">split</a></code> will delete
whitespace from the start of the subject string before it's operated
on.  What is considered whitespace depends on if the subject is a
UTF-8 string and if the <code class="inline"><span class="w">RXf_PMf_LOCALE</span></code>
 flag is set.</p>
<p>If RXf_WHITE is set in addition to this flag, <code class="inline"><a class="l_k" href="functions/split.html">split</a></code> will behave like
<code class="inline"><a class="l_k" href="functions/split.html">split</a> <span class="q">&quot; &quot;</span></code>
 under the Perl engine.</p>
</li>
<li><a name="RXf_START_ONLY"></a><b>RXf_START_ONLY</b>
<p>Tells the split operator to split the target string on newlines
(<code class="inline">\<span class="w">n</span></code>
) without invoking the regex engine.</p>
<p>Perl's engine sets this if the pattern is <code class="inline"><span class="q">/^/</span></code>
 (<code class="inline"><span class="w">plen</span> == <span class="n">1</span> &amp;&amp; <span class="i">*exp</span>
== <span class="q">'^'</span></code>
), even under <code class="inline"><span class="q">/^/s</span></code>
; see <a href="perlfunc.html">split</a>.  Of course a
different regex engine might want to use the same optimizations
with a different syntax.</p>
</li>
<li><a name="RXf_WHITE"></a><b>RXf_WHITE</b>
<p>Tells the split operator to split the target string on whitespace
without invoking the regex engine.  The definition of whitespace varies
depending on if the target string is a UTF-8 string and on
if RXf_PMf_LOCALE is set.</p>
<p>Perl's engine sets this flag if the pattern is <code class="inline">\s+</code>.</p>
</li>
<li><a name="RXf_NULL"></a><b>RXf_NULL</b>
<p>Tells the split operator to split the target string on
characters.  The definition of character varies depending on if
the target string is a UTF-8 string.</p>
<p>Perl's engine sets this flag on empty patterns, this optimization
makes <code class="inline"><a class="l_k" href="functions/split.html">split</a> <span class="q">//</span></code>
 much faster than it would otherwise be.  It's even
faster than <code class="inline"><a class="l_k" href="functions/unpack.html">unpack</a></code>.</p>
</li>
<li><a name="RXf_NO_INPLACE_SUBST"></a><b>RXf_NO_INPLACE_SUBST</b>
<p>Added in perl 5.18.0, this flag indicates that a regular expression might
perform an operation that would interfere with inplace substitution. For
instance it might contain lookbehind, or assign to non-magical variables
(such as $REGMARK and $REGERROR) during matching.  <code class="inline"><a class="l_k" href="functions/s.html">s///</a></code> will skip
certain optimisations when this is set.</p>
</li>
</ul>
<a name="exec"></a><h2>exec</h2>
<pre class="verbatim"><ol><li>    <span class="w">I32</span> <a class="l_k" href="functions/exec.html">exec</a><span class="s">(</span><span class="i">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>             <span class="w">char</span> *<span class="w">stringarg</span><span class="cm">,</span> <span class="w">char</span>* <span class="w">strend</span><span class="cm">,</span> <span class="w">char</span>* <span class="w">strbeg</span><span class="cm">,</span></li><li>             <span class="w">SSize_t</span> <span class="w">minend</span><span class="cm">,</span> <span class="w">SV</span>* <span class="w">sv</span><span class="cm">,</span></li><li>             <span class="w">void</span>* <span class="w">data</span><span class="cm">,</span> <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Execute a regexp. The arguments are</p>
<ul>
<li><a name="rx"></a><b>rx</b>
<p>The regular expression to execute.</p>
</li>
<li><a name="sv"></a><b>sv</b>
<p>This is the SV to be matched against.  Note that the
actual char array to be matched against is supplied by the arguments
described below; the SV is just used to determine UTF8ness, <code class="inline"><a class="l_k" href="functions/pos.html">pos()</a></code> etc.</p>
</li>
<li><a name="strbeg"></a><b>strbeg</b>
<p>Pointer to the physical start of the string.</p>
</li>
<li><a name="strend"></a><b>strend</b>
<p>Pointer to the character following the physical end of the string (i.e.
the <code class="inline">\<span class="n">0</span></code>
, if any).</p>
</li>
<li><a name="stringarg"></a><b>stringarg</b>
<p>Pointer to the position in the string where matching should start; it might
not be equal to <code class="inline"><span class="w">strbeg</span></code>
 (for example in a later iteration of <code class="inline"><span class="q">/.../g</span></code>
).</p>
</li>
<li><a name="minend"></a><b>minend</b>
<p>Minimum length of string (measured in bytes from <code class="inline"><span class="w">stringarg</span></code>
) that must
match; if the engine reaches the end of the match but hasn't reached this
position in the string, it should fail.</p>
</li>
<li><a name="data"></a><b>data</b>
<p>Optimisation data; subject to change.</p>
</li>
<li><a name="flags"></a><b>flags</b>
<p>Optimisation flags; subject to change.</p>
</li>
</ul>
<a name="intuit"></a><h2>intuit</h2>
<pre class="verbatim"><ol><li>    <span class="w">char</span>* <span class="i">intuit</span><span class="s">(</span><span class="w">pTHX_</span></li><li>		<span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>		<span class="w">SV</span> *<span class="w">sv</span><span class="cm">,</span></li><li>		<span class="w">const</span> <span class="w">char</span> * <span class="w">const</span> <span class="w">strbeg</span><span class="cm">,</span></li><li>		<span class="w">char</span> *<span class="w">strpos</span><span class="cm">,</span></li><li>		<span class="w">char</span> *<span class="w">strend</span><span class="cm">,</span></li><li>		<span class="w">const</span> <span class="w">U32</span> <span class="w">flags</span><span class="cm">,</span></li><li>		<span class="w">struct</span> <span class="w">re_scream_pos_data_s</span> *<span class="w">data</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Find the start position where a regex match should be attempted,
or possibly if the regex engine should not be run because the
pattern can't match.  This is called, as appropriate, by the core,
depending on the values of the <code class="inline"><span class="w">extflags</span></code>
 member of the <code class="inline"><span class="w">regexp</span></code>

structure.</p>
<p>Arguments:</p>
<pre class="verbatim"><ol><li>    <span class="j">rx:</span>     <span class="w">the</span> <span class="w">regex</span> <span class="w">to</span> <span class="w">match</span> <span class="w">against</span></li><li>    <span class="w">sv</span><span class="co">:</span>     <span class="w">the</span> <span class="w">SV</span> <span class="w">being</span> <span class="w">matched</span><span class="co">:</span> <span class="w">only</span> <span class="w">used</span> <a class="l_k" href="functions/for.html">for</a> <span class="w">utf8</span> <span class="w">flag</span><span class="sc">;</span> <span class="w">the</span> <span class="w">string</span></li><li>	    <span class="w">itself</span> <span class="w">is</span> <span class="w">accessed</span> <span class="w">via</span> <span class="w">the</span> <span class="w">pointers</span> <span class="w">below</span>. <span class="w">Note</span> <span class="w">that</span> <span class="w">on</span></li><li>	    <span class="w">something</span> <span class="w">like</span> <span class="w">an</span> <span class="w">overloaded</span> <span class="w">SV</span><span class="cm">,</span> <span class="i">SvPOK</span><span class="s">(</span><span class="w">sv</span><span class="s">)</span> <span class="w">may</span> <span class="w">be</span> <span class="w">false</span></li><li>	    <a class="l_k" href="functions/and.html">and</a> <span class="w">the</span> <span class="w">string</span> <span class="w">pointers</span> <span class="w">may</span> <span class="w">point</span> <span class="w">to</span> <span class="w">something</span> <span class="w">unrelated</span> <span class="w">to</span></li><li>	    <span class="w">the</span> <span class="w">SV</span> <span class="w">itself</span>.</li><li>    <span class="w">strbeg</span><span class="co">:</span> <span class="w">real</span> <span class="w">beginning</span> <span class="w">of</span> <span class="w">string</span></li><li>    <span class="w">strpos</span><span class="co">:</span> <span class="w">the</span> <span class="w">point</span> <span class="w">in</span> <span class="w">the</span> <span class="w">string</span> <span class="w">at</span> <span class="w">which</span> <span class="w">to</span> <span class="w">begin</span> <span class="w">matching</span></li><li>    <span class="w">strend</span><span class="co">:</span> <span class="w">pointer</span> <span class="w">to</span> <span class="w">the</span> <span class="w">byte</span> <span class="w">following</span> <span class="w">the</span> <a class="l_k" href="functions/last.html">last</a> <span class="j">char</span> <span class="w">of</span> <span class="w">the</span> <span class="w">string</span></li><li>    <span class="w">flags</span>   <span class="w">currently</span> <span class="w">unused</span><span class="sc">;</span> <span class="w">set</span> <span class="w">to</span> <span class="n">0</span></li><li>    <span class="w">data</span><span class="co">:</span>   <span class="w">currently</span> <span class="w">unused</span><span class="sc">;</span> <span class="w">set</span> <span class="w">to</span> <span class="w">NULL</span></li></ol></pre><a name="checkstr"></a><h2>checkstr</h2>
<pre class="verbatim"><ol><li>    <span class="w">SV</span>*	<span class="i">checkstr</span><span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Return a SV containing a string that must appear in the pattern. Used
by <code class="inline"><a class="l_k" href="functions/split.html">split</a></code> for optimising matches.</p>
<a name="free"></a><h2>free</h2>
<pre class="verbatim"><ol><li>    <span class="w">void</span> <span class="i">free</span><span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Called by Perl when it is freeing a regexp pattern so that the engine
can release any resources pointed to by the <code class="inline"><span class="w">pprivate</span></code>
 member of the
<code class="inline"><span class="w">regexp</span></code>
 structure.  This is only responsible for freeing private data;
Perl will handle releasing anything else contained in the <code class="inline"><span class="w">regexp</span></code>
 structure.</p>
<a name="Numbered-capture-callbacks"></a><h2>Numbered capture callbacks</h2>
<p>Called to get/set the value of <code class="inline"><span class="i">$`</span></code>
, <code class="inline"><span class="i">$&#39;</span></code>
, <code class="inline"><span class="i">$&amp;</span></code>
 and their named
equivalents, ${^PREMATCH}, ${^POSTMATCH} and ${^MATCH}, as well as the
numbered capture groups (<code class="inline"><span class="i">$1</span></code>
, <code class="inline"><span class="i">$2</span></code>
, ...).</p>
<p>The <code class="inline"><span class="w">paren</span></code>
 parameter will be <code class="inline"><span class="n">1</span></code>
 for <code class="inline"><span class="i">$1</span></code>
, <code class="inline"><span class="n">2</span></code>
 for <code class="inline"><span class="i">$2</span></code>
 and so
forth, and have these symbolic values for the special variables:</p>
<pre class="verbatim"><ol><li>    <span class="i">$</span>{<span class="w">^PREMATCH</span>}  <span class="w">RX_BUFF_IDX_CARET_PREMATCH</span></li><li>    <span class="i">$</span>{<span class="w">^POSTMATCH</span>} <span class="w">RX_BUFF_IDX_CARET_POSTMATCH</span></li><li>    <span class="i">$</span>{<span class="w">^MATCH</span>}     <span class="w">RX_BUFF_IDX_CARET_FULLMATCH</span></li><li>    <span class="i">$`</span>            <span class="w">RX_BUFF_IDX_PREMATCH</span></li><li>    <span class="i">$&#39;</span>            <span class="w">RX_BUFF_IDX_POSTMATCH</span></li><li>    <span class="i">$&amp;</span>            <span class="w">RX_BUFF_IDX_FULLMATCH</span></li></ol></pre><p>Note that in Perl 5.17.3 and earlier, the last three constants were also
used for the caret variants of the variables.</p>
<p>The names have been chosen by analogy with <a href="Tie/Scalar.html">Tie::Scalar</a> methods
names with an additional <b>LENGTH</b> callback for efficiency.  However
named capture variables are currently not tied internally but
implemented via magic.</p>
<a name="numbered_buff_FETCH"></a><h3>numbered_buff_FETCH</h3>
<pre class="verbatim"><ol><li>    <span class="w">void</span> <span class="i">numbered_buff_FETCH</span><span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span> <span class="w">const</span> <span class="w">I32</span> <span class="w">paren</span><span class="cm">,</span></li><li>                             <span class="w">SV</span> * <span class="w">const</span> <span class="w">sv</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Fetch a specified numbered capture.  <code class="inline"><span class="w">sv</span></code>
 should be set to the scalar
to return, the scalar is passed as an argument rather than being
returned from the function because when it's called Perl already has a
scalar to store the value, creating another one would be
redundant.  The scalar can be set with <code class="inline"><span class="w">sv_setsv</span></code>
, <code class="inline"><span class="w">sv_setpvn</span></code>
 and
friends, see <a href="perlapi.html">perlapi</a>.</p>
<p>This callback is where Perl untaints its own capture variables under
taint mode (see <a href="perlsec.html">perlsec</a>).  See the <code class="inline"><span class="w">Perl_reg_numbered_buff_fetch</span></code>

function in <i>regcomp.c</i> for how to untaint capture variables if
that's something you'd like your engine to do as well.</p>
<a name="numbered_buff_STORE"></a><h3>numbered_buff_STORE</h3>
<pre class="verbatim"><ol><li>    <span class="w">void</span>    <span class="s">(</span><span class="i">*numbered_buff_STORE</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                                    <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                                    <span class="w">const</span> <span class="w">I32</span> <span class="w">paren</span><span class="cm">,</span></li><li>                                    <span class="w">SV</span> <span class="w">const</span> * <span class="w">const</span> <span class="w">value</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Set the value of a numbered capture variable.  <code class="inline"><span class="w">value</span></code>
 is the scalar
that is to be used as the new value.  It's up to the engine to make
sure this is used as the new value (or reject it).</p>
<p>Example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><span class="q">&quot;ook&quot;</span> =~ <span class="q">/(o*)/</span><span class="s">)</span> <span class="s">{</span></li><li>        <span class="c"># &#39;paren&#39; will be &#39;1&#39; and &#39;value&#39; will be &#39;ee&#39;</span></li><li>        <span class="i">$1</span> =~ <span class="q">tr/o/e/</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Perl's own engine will croak on any attempt to modify the capture
variables, to do this in another engine use the following callback
(copied from <code class="inline"><span class="w">Perl_reg_numbered_buff_store</span></code>
):</p>
<pre class="verbatim"><ol><li>    <span class="w">void</span></li><li>    <span class="i">Example_reg_numbered_buff_store</span><span class="s">(</span><span class="w">pTHX_</span></li><li>                                    <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                                    <span class="w">const</span> <span class="w">I32</span> <span class="w">paren</span><span class="cm">,</span></li><li>                                    <span class="w">SV</span> <span class="w">const</span> * <span class="w">const</span> <span class="w">value</span><span class="s">)</span></li><li>    <span class="s">{</span></li><li>        <span class="i">PERL_UNUSED_ARG</span><span class="s">(</span><span class="w">rx</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="i">PERL_UNUSED_ARG</span><span class="s">(</span><span class="w">paren</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="i">PERL_UNUSED_ARG</span><span class="s">(</span><span class="w">value</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>        <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span>!<span class="w">PL_localizing</span><span class="s">)</span></li><li>            <span class="i">Perl_croak</span><span class="s">(</span><span class="w">aTHX_</span> <span class="w">PL_no_modify</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Actually Perl will not <i>always</i> croak in a statement that looks
like it would modify a numbered capture variable.  This is because the
STORE callback will not be called if Perl can determine that it
doesn't have to modify the value.  This is exactly how tied variables
behave in the same situation:</p>
<pre class="verbatim"><ol><li><a name="package-CaptureVar"></a>    package <span class="i">CaptureVar</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">parent</span> <span class="q">&#39;Tie::Scalar&#39;</span><span class="sc">;</span></li><li></li><li><a name="TIESCALAR"></a>    sub <span class="m">TIESCALAR</span> <span class="s">{</span> <a class="l_k" href="functions/bless.html">bless</a> <span class="s">[</span><span class="s">]</span> <span class="s">}</span></li><li><a name="FETCH"></a>    sub <span class="m">FETCH</span> <span class="s">{</span> <a class="l_k" href="functions/undef.html">undef</a> <span class="s">}</span></li><li><a name="STORE"></a>    sub <span class="m">STORE</span> <span class="s">{</span> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;This doesn&#39;t get called&quot;</span> <span class="s">}</span></li><li></li><li><a name="package-main"></a>    package <span class="i">main</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/tie.html">tie</a> <a class="l_k" href="functions/my.html">my</a> <span class="i">$sv</span> <span class="cm">=&gt;</span> <span class="q">&quot;CaptureVar&quot;</span><span class="sc">;</span></li><li>    <span class="i">$sv</span> =~ <span class="q">y/a/b/</span><span class="sc">;</span></li></ol></pre><p>Because <code class="inline"><span class="i">$sv</span></code>
 is <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> when the <code class="inline"><a class="l_k" href="functions/y.html">y///</a></code> operator is applied to it,
the transliteration won't actually execute and the program won't
<code class="inline"><a class="l_k" href="functions/die.html">die</a></code>.  This is different to how 5.8 and earlier versions behaved
since the capture variables were READONLY variables then; now they'll
just die when assigned to in the default engine.</p>
<a name="numbered_buff_LENGTH"></a><h3>numbered_buff_LENGTH</h3>
<pre class="verbatim"><ol><li>    <span class="w">I32</span> <span class="w">numbered_buff_LENGTH</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                              <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                              <span class="w">const</span> <span class="w">SV</span> * <span class="w">const</span> <span class="w">sv</span><span class="cm">,</span></li><li>                              <span class="w">const</span> <span class="w">I32</span> <span class="w">paren</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Get the <code class="inline"><a class="l_k" href="functions/length.html">length</a></code> of a capture variable.  There's a special callback
for this so that Perl doesn't have to do a FETCH and run <code class="inline"><a class="l_k" href="functions/length.html">length</a></code> on
the result, since the length is (in Perl's case) known from an offset
stored in <code class="inline"><span class="w">rx</span><span class="w">-&gt;offs</span></code>
, this is much more efficient:</p>
<pre class="verbatim"><ol><li>    <span class="w">I32</span> <span class="w">s1</span>  = <span class="w">rx</span><span class="w">-&gt;offs</span>[<span class="w">paren</span>].<span class="w">start</span><span class="sc">;</span></li><li>    <span class="w">I32</span> <span class="w">s2</span>  = <span class="w">rx</span><span class="w">-&gt;offs</span>[<span class="w">paren</span>].<span class="w">end</span><span class="sc">;</span></li><li>    <span class="w">I32</span> <span class="w">len</span> = <span class="w">t1</span> - <span class="w">s1</span><span class="sc">;</span></li></ol></pre><p>This is a little bit more complex in the case of UTF-8, see what
<code class="inline"><span class="w">Perl_reg_numbered_buff_length</span></code>
 does with
<a href="perlapi.html#is_utf8_string_loclen">is_utf8_string_loclen</a>.</p>
<a name="Named-capture-callbacks"></a><h2>Named capture callbacks</h2>
<p>Called to get/set the value of <code class="inline"><span class="i">%+</span></code>
 and <code class="inline"><span class="i">%-</span></code>
, as well as by some
utility functions in <a href="re.html">re</a>.</p>
<p>There are two callbacks, <code class="inline"><span class="w">named_buff</span></code>
 is called in all the cases the
FETCH, STORE, DELETE, CLEAR, EXISTS and SCALAR <a href="Tie/Hash.html">Tie::Hash</a> callbacks
would be on changes to <code class="inline"><span class="i">%+</span></code>
 and <code class="inline"><span class="i">%-</span></code>
 and <code class="inline"><span class="w">named_buff_iter</span></code>
 in the
same cases as FIRSTKEY and NEXTKEY.</p>
<p>The <code class="inline"><span class="w">flags</span></code>
 parameter can be used to determine which of these
operations the callbacks should respond to.  The following flags are
currently defined:</p>
<p>Which <a href="Tie/Hash.html">Tie::Hash</a> operation is being performed from the Perl level on
<code class="inline"><span class="i">%+</span></code>
 or <code class="inline"><span class="i">%+</span></code>
, if any:</p>
<pre class="verbatim"><ol><li>    <span class="w">RXapif_FETCH</span></li><li>    <span class="w">RXapif_STORE</span></li><li>    <span class="w">RXapif_DELETE</span></li><li>    <span class="w">RXapif_CLEAR</span></li><li>    <span class="w">RXapif_EXISTS</span></li><li>    <span class="w">RXapif_SCALAR</span></li><li>    <span class="w">RXapif_FIRSTKEY</span></li><li>    <span class="w">RXapif_NEXTKEY</span></li></ol></pre><p>If <code class="inline"><span class="i">%+</span></code>
 or <code class="inline"><span class="i">%-</span></code>
 is being operated on, if any.</p>
<pre class="verbatim"><ol><li>    RXapif_ONE /* %+ */</li><li>    RXapif_ALL /* %- */</li></ol></pre><p>If this is being called as <code class="inline"><span class="w">re::regname</span></code>
, <code class="inline"><span class="w">re::regnames</span></code>
 or
<code class="inline"><span class="w">re::regnames_count</span></code>
, if any.  The first two will be combined with
<code class="inline"><span class="w">RXapif_ONE</span></code>
 or <code class="inline"><span class="w">RXapif_ALL</span></code>
.</p>
<pre class="verbatim"><ol><li>    <span class="w">RXapif_REGNAME</span></li><li>    <span class="w">RXapif_REGNAMES</span></li><li>    <span class="w">RXapif_REGNAMES_COUNT</span></li></ol></pre><p>Internally <code class="inline"><span class="i">%+</span></code>
 and <code class="inline"><span class="i">%-</span></code>
 are implemented with a real tied interface
via <a href="Tie/Hash/NamedCapture.html">Tie::Hash::NamedCapture</a>.  The methods in that package will call
back into these functions.  However the usage of
<a href="Tie/Hash/NamedCapture.html">Tie::Hash::NamedCapture</a> for this purpose might change in future
releases.  For instance this might be implemented by magic instead
(would need an extension to mgvtbl).</p>
<a name="named_buff"></a><h3>named_buff</h3>
<pre class="verbatim"><ol><li>    SV*     (*named_buff) (pTHX_ REGEXP * const rx, SV * const key,</li><li>                           SV * const value, U32 flags);</li></ol></pre><a name="named_buff_iter"></a><h3>named_buff_iter</h3>
<pre class="verbatim"><ol><li>    <span class="w">SV</span>*     <span class="s">(</span><span class="i">*named_buff_iter</span><span class="s">)</span> <span class="s">(</span><span class="w">pTHX_</span></li><li>                                <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span></li><li>                                <span class="w">const</span> <span class="w">SV</span> * <span class="w">const</span> <span class="w">lastkey</span><span class="cm">,</span></li><li>                                <span class="w">const</span> <span class="w">U32</span> <span class="w">flags</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="qr_package"></a><h2>qr_package</h2>
<pre class="verbatim"><ol><li>    <span class="w">SV</span>* <span class="i">qr_package</span><span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The package the qr// magic object is blessed into (as seen by <code class="inline"><a class="l_k" href="functions/ref.html">ref</a>
<span class="q">qr//</span></code>
).  It is recommended that engines change this to their package
name for identification regardless of if they implement methods
on the object.</p>
<p>The package this method returns should also have the internal
<code class="inline"><span class="w">Regexp</span></code>
 package in its <code class="inline"><span class="i">@ISA</span></code>
.  <code class="inline"><a class="l_k" href="functions/qr.html">qr//->isa("Regexp")</a></code> should always
be true regardless of what engine is being used.</p>
<p>Example implementation might be:</p>
<pre class="verbatim"><ol><li>    SV*</li><li>    Example_qr_package(pTHX_ REGEXP * const rx)</li><li>    {</li><li>    	PERL_UNUSED_ARG(rx);</li><li>    	return newSVpvs("re::engine::Example");</li><li>    }</li></ol></pre><p>Any method calls on an object created with <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code> will be dispatched to the
package as a normal object.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">re::engine::Example</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$re</span> = <span class="q">qr//</span><span class="sc">;</span></li><li>    <span class="i">$re</span><span class="i">-&gt;meth</span><span class="sc">;</span> <span class="c"># dispatched to re::engine::Example::meth()</span></li></ol></pre><p>To retrieve the <code class="inline"><span class="w">REGEXP</span></code>
 object from the scalar in an XS function use
the <code class="inline"><span class="w">SvRX</span></code>
 macro, see <a href="perlapi.html#REGEXP-Functions">REGEXP Functions in perlapi</a>.</p>
<pre class="verbatim"><ol><li>    void meth(SV * rv)</li><li>    PPCODE:</li><li>        REGEXP * re = SvRX(sv);</li></ol></pre><a name="dupe"></a><h2>dupe</h2>
<pre class="verbatim"><ol><li>    <span class="w">void</span>* <span class="i">dupe</span><span class="s">(</span><span class="w">pTHX_</span> <span class="w">REGEXP</span> * <span class="w">const</span> <span class="w">rx</span><span class="cm">,</span> <span class="w">CLONE_PARAMS</span> *<span class="w">param</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>On threaded builds a regexp may need to be duplicated so that the pattern
can be used by multiple threads.  This routine is expected to handle the
duplication of any private data pointed to by the <code class="inline"><span class="w">pprivate</span></code>
 member of
the <code class="inline"><span class="w">regexp</span></code>
 structure.  It will be called with the preconstructed new
<code class="inline"><span class="w">regexp</span></code>
 structure as an argument, the <code class="inline"><span class="w">pprivate</span></code>
 member will point at
the <b>old</b> private structure, and it is this routine's responsibility to
construct a copy and return a pointer to it (which Perl will then use to
overwrite the field as passed to this routine.)</p>
<p>This allows the engine to dupe its private data but also if necessary
modify the final structure if it really must.</p>
<p>On unthreaded builds this field doesn't exist.</p>
<a name="op_comp"></a><h2>op_comp</h2>
<p>This is private to the Perl core and subject to change. Should be left
null.</p>
<a name="The-REGEXP-structure"></a><h1>The REGEXP structure</h1>
<p>The REGEXP struct is defined in <i>regexp.h</i>.
All regex engines must be able to
correctly build such a structure in their <a href="#comp">comp</a> routine.</p>
<p>The REGEXP structure contains all the data that Perl needs to be aware of
to properly work with the regular expression.  It includes data about
optimisations that Perl can use to determine if the regex engine should
really be used, and various other control info that is needed to properly
execute patterns in various contexts, such as if the pattern anchored in
some way, or what flags were used during the compile, or if the
program contains special constructs that Perl needs to be aware of.</p>
<p>In addition it contains two fields that are intended for the private
use of the regex engine that compiled the pattern.  These are the
<code class="inline"><span class="w">intflags</span></code>
 and <code class="inline"><span class="w">pprivate</span></code>
 members.  <code class="inline"><span class="w">pprivate</span></code>
 is a void pointer to
an arbitrary structure, whose use and management is the responsibility
of the compiling engine.  Perl will never modify either of these
values.</p>
<pre class="verbatim"><ol><li>    <span class="w">typedef</span> <span class="w">struct</span> <span class="i">regexp</span> <span class="s">{</span></li><li>        <span class="q">/* what engine created this regexp? */</span></li><li>        <span class="w">const</span> <span class="w">struct</span> <span class="w">regexp_engine</span>* <span class="w">engine</span><span class="sc">;</span></li><li></li><li>        <span class="q">/* what re is this a lightweight copy of? */</span></li><li>        <span class="w">struct</span> <span class="w">regexp</span>* <span class="w">mother_re</span><span class="sc">;</span></li><li></li><li>        <span class="q">/* Information about the match that the Perl core uses to manage</span></li><li>         <span class="q">         * things */</span></li><li>        <span class="w">U32</span> <span class="w">extflags</span><span class="sc">;</span>   <span class="q">/* Flags used both externally and internally */</span></li><li>	<span class="w">I32</span> <span class="w">minlen</span><span class="sc">;</span>	<span class="q">/* mininum possible number of chars in */</span></li><li>                           <span class="w">string</span> <span class="w">to</span> <span class="w">match</span> *<span class="q">/</span></li><li>	<span class="q">	I32 minlenret;	/</span>* <span class="w">mininum</span> <span class="w">possible</span> <span class="w">number</span> <span class="w">of</span> <span class="w">chars</span> <span class="w">in</span> <span class="i">$&amp;</span> <span class="i">*/</span></li><li>        <span class="w">U32</span> <span class="w">gofs</span><span class="sc">;</span>       <span class="q">/* chars left of pos that we search from */</span></li><li></li><li>        /<span class="i">* substring</span> <span class="w">data</span> <span class="w">about</span> <span class="w">strings</span> <span class="w">that</span> <span class="w">must</span> <span class="w">appear</span></li><li>           <span class="w">in</span> <span class="w">the</span> <span class="w">final</span> <span class="w">match</span><span class="cm">,</span> <span class="w">used</span> <a class="l_k" href="functions/for.html">for</a> <span class="w">optimisations</span> *<span class="q">/</span></li><li>        <span class="q">        struct reg_substr_data *substrs;</span></li><li></li><li>        <span class="q">        U32 nparens;  /</span>* <span class="w">number</span> <span class="w">of</span> <span class="w">capture</span> <span class="w">groups</span> *<span class="q">/</span></li><li></li><li>        <span class="q">        /</span>* <span class="w">private</span> <span class="w">engine</span> <span class="w">specific</span> <span class="w">data</span> *<span class="q">/</span></li><li>        <span class="q">        U32 intflags;   /</span>* <span class="w">Engine</span> <span class="w">Specific</span> <span class="w">Internal</span> <span class="w">flags</span> *<span class="q">/</span></li><li>        <span class="q">        void *pprivate; /</span>* <span class="w">Data</span> <span class="w">private</span> <span class="w">to</span> <span class="w">the</span> <span class="w">regex</span> <span class="w">engine</span> <span class="w">which</span> </li><li>                           <span class="w">created</span> <span class="w">this</span> <span class="w">object</span>. <span class="i">*/</span></li><li></li><li>        /<span class="i">* Data</span> <span class="w">about</span> <span class="w">the</span> <a class="l_k" href="functions/last.html">last</a><span class="q">/current match. These are modified during</span></li><li>         <span class="q">         * matching*/</span></li><li>        <span class="w">U32</span> <span class="w">lastparen</span><span class="sc">;</span>            <span class="q">/* highest close paren matched ($+) */</span></li><li>        <span class="w">U32</span> <span class="w">lastcloseparen</span><span class="sc">;</span>       <span class="q">/* last close paren matched ($^N) */</span></li><li>        <span class="w">regexp_paren_pair</span> *<span class="w">swap</span><span class="sc">;</span>  <span class="q">/* Swap copy of *offs */</span></li><li>        <span class="w">regexp_paren_pair</span> *<span class="w">offs</span><span class="sc">;</span>  <span class="q">/* Array of offsets for (@-) and</span></li><li>                                     <span class="q">                                     (@+) */</span></li><li></li><li>        <span class="w">char</span> *<span class="w">subbeg</span><span class="sc">;</span>  <span class="q">/* saved or original string so \digit works</span></li><li>                          <span class="q">                          forever. */</span></li><li>        <span class="w">SV_SAVED_COPY</span>  <span class="q">/* If non-NULL, SV which is COW from original */</span></li><li>        <span class="w">I32</span> <span class="w">sublen</span><span class="sc">;</span>    <span class="q">/* Length of string pointed by subbeg */</span></li><li>        <span class="w">I32</span> <span class="w">suboffset</span><span class="sc">;</span>	<span class="q">/* byte offset of subbeg from logical start of</span></li><li>                           <span class="q">                           str */</span></li><li>	<span class="w">I32</span> <span class="w">subcoffset</span><span class="sc">;</span>	<span class="q">/* suboffset equiv, but in chars (for @-/</span><span class="i">@+</span><span class="p">)</span> *<span class="q">/</span></li><li></li><li>        <span class="q">        /</span>* <span class="w">Information</span> <span class="w">about</span> <span class="w">the</span> <span class="w">match</span> <span class="w">that</span> <span class="w">isn&#39;t</span> <span class="w">often</span> <span class="w">used</span> *<span class="q">/</span></li><li>        <span class="q">        I32 prelen;           /</span>* <a class="l_k" href="functions/length.html">length</a> <span class="w">of</span> <span class="w">precomp</span> *<span class="q">/</span></li><li>        <span class="q">        const char *precomp;  /</span>* <span class="w">pre</span>-<span class="w">compilation</span> <span class="w">regular</span> <span class="w">expression</span> *<span class="q">/</span></li><li></li><li>        <span class="q">        char *wrapped;  /</span>* <span class="w">wrapped</span> <span class="w">version</span> <span class="w">of</span> <span class="w">the</span> <span class="w">pattern</span> *<span class="q">/</span></li><li>        <span class="q">        I32 wraplen;    /</span>* <a class="l_k" href="functions/length.html">length</a> <span class="w">of</span> <span class="w">wrapped</span> *<span class="q">/</span></li><li></li><li>        <span class="q">        I32 seen_evals;   /</span>* <span class="w">number</span> <span class="w">of</span> <a class="l_k" href="functions/eval.html">eval</a> <span class="w">groups</span> <span class="w">in</span> <span class="w">the</span> <span class="w">pattern</span> - <a class="l_k" href="functions/for.html">for</a></li><li>                             <span class="w">security</span> <span class="w">checks</span> *<span class="q">/</span></li><li>        <span class="q">        HV *paren_names;  /</span>* <span class="w">Optional</span> <span class="w">hash</span> <span class="w">of</span> <span class="w">paren</span> <span class="w">names</span> *<span class="q">/</span></li><li></li><li>        <span class="q">        /</span>* <span class="w">Refcount</span> <span class="w">of</span> <span class="w">this</span> <span class="w">regexp</span> *<span class="q">/</span></li><li>        <span class="q">        I32 refcnt;             /</span>* <span class="w">Refcount</span> <span class="w">of</span> <span class="w">this</span> <span class="w">regexp</span> *<span class="q">/</span></li><li>    <span class="q">    } regexp;</span></li></ol></pre><p>The fields are discussed in more detail below:</p>
<a name="engine"></a><h2><code class="inline"><span class="w">engine</span></code>
</h2>
<p>This field points at a <code class="inline"><span class="w">regexp_engine</span></code>
 structure which contains pointers
to the subroutines that are to be used for performing a match.  It
is the compiling routine's responsibility to populate this field before
returning the regexp object.</p>
<p>Internally this is set to <code class="inline"><span class="w">NULL</span></code>
 unless a custom engine is specified in
<code class="inline"><span class="i">$^H</span>{<span class="w">regcomp</span>}</code>
, Perl's own set of callbacks can be accessed in the struct
pointed to by <code class="inline"><span class="w">RE_ENGINE_PTR</span></code>
.</p>
<a name="mother_re"></a><h2><code class="inline"><span class="w">mother_re</span></code>
</h2>
<p>TODO, see <a href="http://www.mail-archive.com/perl5-changes@perl.org/msg17328.html">http://www.mail-archive.com/perl5-changes@perl.org/msg17328.html</a></p>
<a name="extflags"></a><h2><code class="inline"><span class="w">extflags</span></code>
</h2>
<p>This will be used by Perl to see what flags the regexp was compiled
with, this will normally be set to the value of the flags parameter by
the <a href="#comp">comp</a> callback.  See the <a href="#comp">comp</a> documentation for
valid flags.</p>
<a name="minlen-minlenret"></a><h2><code class="inline"><span class="w">minlen</span></code>
 <code class="inline"><span class="w">minlenret</span></code>
</h2>
<p>The minimum string length (in characters) required for the pattern to match.
This is used to
prune the search space by not bothering to match any closer to the end of a
string than would allow a match.  For instance there is no point in even
starting the regex engine if the minlen is 10 but the string is only 5
characters long.  There is no way that the pattern can match.</p>
<p><code class="inline"><span class="w">minlenret</span></code>
 is the minimum length (in characters) of the string that would
be found in $&amp; after a match.</p>
<p>The difference between <code class="inline"><span class="w">minlen</span></code>
 and <code class="inline"><span class="w">minlenret</span></code>
 can be seen in the
following pattern:</p>
<pre class="verbatim"><ol><li>    <span class="q">/ns(?=\d)/</span></li></ol></pre><p>where the <code class="inline"><span class="w">minlen</span></code>
 would be 3 but <code class="inline"><span class="w">minlenret</span></code>
 would only be 2 as the \d is
required to match but is not actually
included in the matched content.  This
distinction is particularly important as the substitution logic uses the
<code class="inline"><span class="w">minlenret</span></code>
 to tell if it can do in-place substitutions (these can
result in considerable speed-up).</p>
<a name="gofs"></a><h2><code class="inline"><span class="w">gofs</span></code>
</h2>
<p>Left offset from pos() to start match at.</p>
<a name="substrs"></a><h2><code class="inline"><span class="w">substrs</span></code>
</h2>
<p>Substring data about strings that must appear in the final match.  This
is currently only used internally by Perl's engine, but might be
used in the future for all engines for optimisations.</p>
<a name="nparens%2c-lastparen%2c-and-lastcloseparen"></a><h2><code class="inline"><span class="w">nparens</span></code>
, <code class="inline"><span class="w">lastparen</span></code>
, and <code class="inline"><span class="w">lastcloseparen</span></code>
</h2>
<p>These fields are used to keep track of how many paren groups could be matched
in the pattern, which was the last open paren to be entered, and which was
the last close paren to be entered.</p>
<a name="intflags"></a><h2><code class="inline"><span class="w">intflags</span></code>
</h2>
<p>The engine's private copy of the flags the pattern was compiled with. Usually
this is the same as <code class="inline"><span class="w">extflags</span></code>
 unless the engine chose to modify one of them.</p>
<a name="pprivate"></a><h2><code class="inline"><span class="w">pprivate</span></code>
</h2>
<p>A void* pointing to an engine-defined
data structure.  The Perl engine uses the
<code class="inline"><span class="w">regexp_internal</span></code>
 structure (see <a href="perlreguts.html#Base-Structures">Base Structures in perlreguts</a>) but a custom
engine should use something else.</p>
<a name="swap"></a><h2><code class="inline"><span class="w">swap</span></code>
</h2>
<p>Unused.  Left in for compatibility with Perl 5.10.0.</p>
<a name="offs"></a><h2><code class="inline"><span class="w">offs</span></code>
</h2>
<p>A <code class="inline"><span class="w">regexp_paren_pair</span></code>
 structure which defines offsets into the string being
matched which correspond to the <code class="inline"><span class="i">$&amp;</span></code>
 and <code class="inline"><span class="i">$1</span></code>
, <code class="inline"><span class="i">$2</span></code>
 etc. captures, the
<code class="inline"><span class="w">regexp_paren_pair</span></code>
 struct is defined as follows:</p>
<pre class="verbatim"><ol><li>    <span class="w">typedef</span> <span class="w">struct</span> <span class="i">regexp_paren_pair</span> <span class="s">{</span></li><li>        <span class="w">I32</span> <span class="w">start</span><span class="sc">;</span></li><li>        <span class="w">I32</span> <span class="w">end</span><span class="sc">;</span></li><li>    <span class="s">}</span> <span class="w">regexp_paren_pair</span><span class="sc">;</span></li></ol></pre><p>If <code class="inline"><span class="i">-&gt;offs</span>[<span class="w">num</span>].<span class="w">start</span></code>
 or <code class="inline"><span class="i">-&gt;offs</span>[<span class="w">num</span>].<span class="w">end</span></code>
 is <code class="inline"><span class="n">-1</span></code>
 then that
capture group did not match.
<code class="inline"><span class="i">-&gt;offs</span>[<span class="n">0</span>].<span class="w">start</span>/<span class="w">end</span></code>
 represents <code class="inline"><span class="i">$&amp;</span></code>
 (or
<code class="inline"><span class="i">$</span>{<span class="w">^MATCH</span>}</code>
 under <code class="inline">/p</code>) and <code class="inline"><span class="i">-&gt;offs</span>[<span class="w">paren</span>].<span class="w">end</span></code>
 matches <code class="inline"><span class="i">$$paren</span></code>
 where
<code class="inline"><span class="i">$paren</span> </code>
= 1&gt;.</p>
<a name="precomp-prelen"></a><h2><code class="inline"><span class="w">precomp</span></code>
 <code class="inline"><span class="w">prelen</span></code>
</h2>
<p>Used for optimisations.  <code class="inline"><span class="w">precomp</span></code>
 holds a copy of the pattern that
was compiled and <code class="inline"><span class="w">prelen</span></code>
 its length.  When a new pattern is to be
compiled (such as inside a loop) the internal <code class="inline"><span class="w">regcomp</span></code>
 operator
checks if the last compiled <code class="inline"><span class="w">REGEXP</span></code>
's <code class="inline"><span class="w">precomp</span></code>
 and <code class="inline"><span class="w">prelen</span></code>

are equivalent to the new one, and if so uses the old pattern instead
of compiling a new one.</p>
<p>The relevant snippet from <code class="inline"><span class="w">Perl_pp_regcomp</span></code>
:</p>
<pre class="verbatim"><ol><li>	if (!re || !re-&gt;precomp || re-&gt;prelen != (I32)len ||</li><li>	    memNE(re-&gt;precomp, t, len))</li><li>        /* Compile a new pattern */</li></ol></pre><a name="paren_names"></a><h2><code class="inline"><span class="w">paren_names</span></code>
</h2>
<p>This is a hash used internally to track named capture groups and their
offsets.  The keys are the names of the buffers the values are dualvars,
with the IV slot holding the number of buffers with the given name and the
pv being an embedded array of I32.  The values may also be contained
independently in the data array in cases where named backreferences are
used.</p>
<a name="substrs"></a><h2><code class="inline"><span class="w">substrs</span></code>
</h2>
<p>Holds information on the longest string that must occur at a fixed
offset from the start of the pattern, and the longest string that must
occur at a floating offset from the start of the pattern.  Used to do
Fast-Boyer-Moore searches on the string to find out if its worth using
the regex engine at all, and if so where in the string to search.</p>
<a name="subbeg-sublen-saved_copy-suboffset-subcoffset"></a><h2><code class="inline"><span class="w">subbeg</span></code>
 <code class="inline"><span class="w">sublen</span></code>
 <code class="inline"><span class="w">saved_copy</span></code>
 <code class="inline"><span class="w">suboffset</span></code>
 <code class="inline"><span class="w">subcoffset</span></code>
</h2>
<p>Used during the execution phase for managing search and replace patterns,
and for providing the text for <code class="inline"><span class="i">$&amp;</span></code>
, <code class="inline"><span class="i">$1</span></code>
 etc. <code class="inline"><span class="w">subbeg</span></code>
 points to a
buffer (either the original string, or a copy in the case of
<code class="inline"><span class="i">RX_MATCH_COPIED</span><span class="s">(</span><span class="w">rx</span><span class="s">)</span></code>
), and <code class="inline"><span class="w">sublen</span></code>
 is the length of the buffer.  The
<code class="inline"><span class="w">RX_OFFS</span></code>
 start and end indices index into this buffer.</p>
<p>In the presence of the <code class="inline"><span class="w">REXEC_COPY_STR</span></code>
 flag, but with the addition of
the <code class="inline"><span class="w">REXEC_COPY_SKIP_PRE</span></code>
 or <code class="inline"><span class="w">REXEC_COPY_SKIP_POST</span></code>
 flags, an engine
can choose not to copy the full buffer (although it must still do so in
the presence of <code class="inline"><span class="w">RXf_PMf_KEEPCOPY</span></code>
 or the relevant bits being set in
<code class="inline"><span class="w">PL_sawampersand</span></code>
).  In this case, it may set <code class="inline"><span class="w">suboffset</span></code>
 to indicate the
number of bytes from the logical start of the buffer to the physical start
(i.e. <code class="inline"><span class="w">subbeg</span></code>
).  It should also set <code class="inline"><span class="w">subcoffset</span></code>
, the number of
characters in the offset. The latter is needed to support <code class="inline"><span class="i">@-</span></code>
 and <code class="inline"><span class="i">@+</span></code>

which work in characters, not bytes.</p>
<a name="wrapped-wraplen"></a><h2><code class="inline"><span class="w">wrapped</span></code>
 <code class="inline"><span class="w">wraplen</span></code>
</h2>
<p>Stores the string <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code> stringifies to. The Perl engine for example
stores <code class="inline"><span class="s">(</span><span class="q">?^:eek)</span></code>
 in the case of <code class="inline"><a class="l_k" href="functions/qr.html">qr/eek/</a></code>.</p>
<p>When using a custom engine that doesn't support the <code class="inline">(?:)</code> construct
for inline modifiers, it's probably best to have <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code> stringify to
the supplied pattern, note that this will create undesired patterns in
cases such as:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$x</span> = <span class="q">qr/a|b/</span><span class="sc">;</span>  <span class="c"># &quot;a|b&quot;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$y</span> = <span class="q">qr/c/i</span><span class="sc">;</span>   <span class="c"># &quot;c&quot;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$z</span> = <span class="q">qr/$x$y/</span><span class="sc">;</span> <span class="c"># &quot;a|bc&quot;</span></li></ol></pre><p>There's no solution for this problem other than making the custom
engine understand a construct like <code class="inline">(?:)</code>.</p>
<a name="seen_evals"></a><h2><code class="inline"><span class="w">seen_evals</span></code>
</h2>
<p>This stores the number of eval groups in
the pattern.  This is used for security
purposes when embedding compiled regexes into larger patterns with <code class="inline"><a class="l_k" href="functions/qr.html">qr//</a></code>.</p>
<a name="refcnt"></a><h2><code class="inline"><span class="w">refcnt</span></code>
</h2>
<p>The number of times the structure is referenced.  When
this falls to 0, the regexp is automatically freed
by a call to pregfree.  This should be set to 1 in
each engine's <a href="#comp">comp</a> routine.</p>
<a name="HISTORY"></a><h1>HISTORY</h1>
<p>Originally part of <a href="perlreguts.html">perlreguts</a>.</p>
<a name="AUTHORS"></a><h1>AUTHORS</h1>
<p>Originally written by Yves Orton, expanded by &#xc6;var Arnfj&#xf6;r&#xf0;
Bjarmason.</p>
<a name="LICENSE"></a><h1>LICENSE</h1>
<p>Copyright 2006 Yves Orton and 2007 &#xc6;var Arnfj&#xf6;r&#xf0; Bjarmason.</p>
<p>This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.</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="#DESCRIPTION">DESCRIPTION</a><li><a href="#Callbacks">Callbacks</a><ul><li><a href="#comp">comp</a><li><a href="#exec">exec</a><li><a href="#intuit">intuit</a><li><a href="#checkstr">checkstr</a><li><a href="#free">free</a><li><a href="#Numbered-capture-callbacks">Numbered capture callbacks</a><li><a href="#Named-capture-callbacks">Named capture callbacks</a><li><a href="#qr_package">qr_package</a><li><a href="#dupe">dupe</a><li><a href="#op_comp">op_comp</a></ul><li><a href="#The-REGEXP-structure">The REGEXP structure</a><ul><li><a href="#engine">engine</a><li><a href="#mother_re">mother_re</a><li><a href="#extflags">extflags</a><li><a href="#minlen-minlenret">minlen minlenret</a><li><a href="#gofs">gofs</a><li><a href="#substrs">substrs</a><li><a href="#nparens%2c-lastparen%2c-and-lastcloseparen">nparens, lastparen, and lastcloseparen</a><li><a href="#intflags">intflags</a><li><a href="#pprivate">pprivate</a><li><a href="#swap">swap</a><li><a href="#offs">offs</a><li><a href="#precomp-prelen">precomp prelen</a><li><a href="#paren_names">paren_names</a><li><a href="#substrs">substrs</a><li><a href="#subbeg-sublen-saved_copy-suboffset-subcoffset">subbeg sublen saved_copy suboffset subcoffset</a><li><a href="#wrapped-wraplen">wrapped wraplen</a><li><a href="#seen_evals">seen_evals</a><li><a href="#refcnt">refcnt</a></ul><li><a href="#HISTORY">HISTORY</a><li><a href="#AUTHORS">AUTHORS</a><li><a href="#LICENSE">LICENSE</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    = 'perlreapi';
  perldoc.pageAddress = 'perlreapi.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>