xref: /openbsd-src/gnu/usr.bin/perl/ext/re/re.pm (revision 5a38ef86d0b61900239c7913d24a05e7b88a58f0)
1package re;
2
3# pragma for controlling the regexp engine
4use strict;
5use warnings;
6
7our $VERSION     = "0.40";
8our @ISA         = qw(Exporter);
9our @EXPORT_OK   = ('regmust',
10                    qw(is_regexp regexp_pattern
11                       regname regnames regnames_count));
12our %EXPORT_OK = map { $_ => 1 } @EXPORT_OK;
13
14my %bitmask = (
15    taint   => 0x00100000, # HINT_RE_TAINT
16    eval    => 0x00200000, # HINT_RE_EVAL
17);
18
19my $flags_hint = 0x02000000; # HINT_RE_FLAGS
20my $PMMOD_SHIFT = 0;
21my %reflags = (
22    m => 1 << ($PMMOD_SHIFT + 0),
23    s => 1 << ($PMMOD_SHIFT + 1),
24    i => 1 << ($PMMOD_SHIFT + 2),
25    x => 1 << ($PMMOD_SHIFT + 3),
26   xx => 1 << ($PMMOD_SHIFT + 4),
27    n => 1 << ($PMMOD_SHIFT + 5),
28    p => 1 << ($PMMOD_SHIFT + 6),
29    strict => 1 << ($PMMOD_SHIFT + 10),
30# special cases:
31    d => 0,
32    l => 1,
33    u => 2,
34    a => 3,
35    aa => 4,
36);
37
38sub setcolor {
39 eval {				# Ignore errors
40  require Term::Cap;
41
42  my $terminal = Tgetent Term::Cap ({OSPEED => 9600}); # Avoid warning.
43  my $props = $ENV{PERL_RE_TC} || 'md,me,so,se,us,ue';
44  my @props = split /,/, $props;
45  my $colors = join "\t", map {$terminal->Tputs($_,1)} @props;
46
47  $colors =~ s/\0//g;
48  $ENV{PERL_RE_COLORS} = $colors;
49 };
50 if ($@) {
51    $ENV{PERL_RE_COLORS} ||= qq'\t\t> <\t> <\t\t';
52 }
53
54}
55
56my %flags = (
57    COMPILE           => 0x0000FF,
58    PARSE             => 0x000001,
59    OPTIMISE          => 0x000002,
60    TRIEC             => 0x000004,
61    DUMP              => 0x000008,
62    FLAGS             => 0x000010,
63    TEST              => 0x000020,
64
65    EXECUTE           => 0x00FF00,
66    INTUIT            => 0x000100,
67    MATCH             => 0x000200,
68    TRIEE             => 0x000400,
69
70    EXTRA             => 0x3FF0000,
71    TRIEM             => 0x0010000,
72    OFFSETS           => 0x0020000,
73    OFFSETSDBG        => 0x0040000,
74    STATE             => 0x0080000,
75    OPTIMISEM         => 0x0100000,
76    STACK             => 0x0280000,
77    BUFFERS           => 0x0400000,
78    GPOS              => 0x0800000,
79    DUMP_PRE_OPTIMIZE => 0x1000000,
80    WILDCARD          => 0x2000000,
81);
82$flags{ALL} = -1 & ~($flags{OFFSETS}
83                    |$flags{OFFSETSDBG}
84                    |$flags{BUFFERS}
85                    |$flags{DUMP_PRE_OPTIMIZE}
86                    |$flags{WILDCARD}
87                    );
88$flags{All} = $flags{all} = $flags{DUMP} | $flags{EXECUTE};
89$flags{Extra} = $flags{EXECUTE} | $flags{COMPILE} | $flags{GPOS};
90$flags{More} = $flags{MORE} =
91                    $flags{All} | $flags{TRIEC} | $flags{TRIEM} | $flags{STATE};
92$flags{State} = $flags{DUMP} | $flags{EXECUTE} | $flags{STATE};
93$flags{TRIE} = $flags{DUMP} | $flags{EXECUTE} | $flags{TRIEC};
94
95if (defined &DynaLoader::boot_DynaLoader) {
96    require XSLoader;
97    XSLoader::load();
98}
99# else we're miniperl
100# We need to work for miniperl, because the XS toolchain uses Text::Wrap, which
101# uses re 'taint'.
102
103sub _load_unload {
104    my ($on)= @_;
105    if ($on) {
106	# We call install() every time, as if we didn't, we wouldn't
107	# "see" any changes to the color environment var since
108	# the last time it was called.
109
110	# install() returns an integer, which if casted properly
111	# in C resolves to a structure containing the regexp
112	# hooks. Setting it to a random integer will guarantee
113	# segfaults.
114	$^H{regcomp} = install();
115    } else {
116        delete $^H{regcomp};
117    }
118}
119
120sub bits {
121    my $on = shift;
122    my $bits = 0;
123    my $turning_all_off = ! @_ && ! $on;
124    my $seen_Debug = 0;
125    my $seen_debug = 0;
126    if ($turning_all_off) {
127
128        # Pretend were called with certain parameters, which are best dealt
129        # with that way.
130        push @_, keys %bitmask; # taint and eval
131        push @_, 'strict';
132    }
133
134    # Process each subpragma parameter
135   ARG:
136    foreach my $idx (0..$#_){
137        my $s=$_[$idx];
138        if ($s eq 'Debug' or $s eq 'Debugcolor') {
139            if (! $seen_Debug) {
140                $seen_Debug = 1;
141
142                # Reset to nothing, and then add what follows.  $seen_Debug
143                # allows, though unlikely someone would do it, more than one
144                # Debug and flags in the arguments
145                ${^RE_DEBUG_FLAGS} = 0;
146            }
147            setcolor() if $s =~/color/i;
148            for my $idx ($idx+1..$#_) {
149                if ($flags{$_[$idx]}) {
150                    if ($on) {
151                        ${^RE_DEBUG_FLAGS} |= $flags{$_[$idx]};
152                    } else {
153                        ${^RE_DEBUG_FLAGS} &= ~ $flags{$_[$idx]};
154                    }
155                } else {
156                    require Carp;
157                    Carp::carp("Unknown \"re\" Debug flag '$_[$idx]', possible flags: ",
158                               join(", ",sort keys %flags ) );
159                }
160            }
161            _load_unload($on ? 1 : ${^RE_DEBUG_FLAGS});
162            last;
163        } elsif ($s eq 'debug' or $s eq 'debugcolor') {
164
165            # These default flags should be kept in sync with the same values
166            # in regcomp.h
167            ${^RE_DEBUG_FLAGS} = $flags{'EXECUTE'} | $flags{'DUMP'};
168	    setcolor() if $s =~/color/i;
169	    _load_unload($on);
170            $seen_debug = 1;
171        } elsif (exists $bitmask{$s}) {
172	    $bits |= $bitmask{$s};
173	} elsif ($EXPORT_OK{$s}) {
174	    require Exporter;
175	    re->export_to_level(2, 're', $s);
176        } elsif ($s eq 'strict') {
177            if ($on) {
178                $^H{reflags} |= $reflags{$s};
179                warnings::warnif('experimental::re_strict',
180                                 "\"use re 'strict'\" is experimental");
181
182                # Turn on warnings if not already done.
183                if (! warnings::enabled('regexp')) {
184                    require warnings;
185                    warnings->import('regexp');
186                    $^H{re_strict} = 1;
187                }
188            }
189            else {
190                $^H{reflags} &= ~$reflags{$s} if $^H{reflags};
191
192                # Turn off warnings if we turned them on.
193                warnings->unimport('regexp') if $^H{re_strict};
194            }
195	    if ($^H{reflags}) {
196                $^H |= $flags_hint;
197            }
198            else {
199                $^H &= ~$flags_hint;
200            }
201	} elsif ($s =~ s/^\///) {
202	    my $reflags = $^H{reflags} || 0;
203	    my $seen_charset;
204            my $x_count = 0;
205	    while ($s =~ m/( . )/gx) {
206                local $_ = $1;
207		if (/[adul]/) {
208                    # The 'a' may be repeated; hide this from the rest of the
209                    # code by counting and getting rid of all of them, then
210                    # changing to 'aa' if there is a repeat.
211                    if ($_ eq 'a') {
212                        my $sav_pos = pos $s;
213                        my $a_count = $s =~ s/a//g;
214                        pos $s = $sav_pos - 1;  # -1 because got rid of the 'a'
215                        if ($a_count > 2) {
216			    require Carp;
217                            Carp::carp(
218                            qq 'The "a" flag may only appear a maximum of twice'
219                            );
220                        }
221                        elsif ($a_count == 2) {
222                            $_ = 'aa';
223                        }
224                    }
225		    if ($on) {
226			if ($seen_charset) {
227			    require Carp;
228                            if ($seen_charset ne $_) {
229                                Carp::carp(
230                                qq 'The "$seen_charset" and "$_" flags '
231                                .qq 'are exclusive'
232                                );
233                            }
234                            else {
235                                Carp::carp(
236                                qq 'The "$seen_charset" flag may not appear '
237                                .qq 'twice'
238                                );
239                            }
240			}
241			$^H{reflags_charset} = $reflags{$_};
242			$seen_charset = $_;
243		    }
244		    else {
245			delete $^H{reflags_charset}
246                                     if defined $^H{reflags_charset}
247                                        && $^H{reflags_charset} == $reflags{$_};
248		    }
249		} elsif (exists $reflags{$_}) {
250                    if ($_ eq 'x') {
251                        $x_count++;
252                        if ($x_count > 2) {
253			    require Carp;
254                            Carp::carp(
255                            qq 'The "x" flag may only appear a maximum of twice'
256                            );
257                        }
258                        elsif ($x_count == 2) {
259                            $_ = 'xx';  # First time through got the /x
260                        }
261                    }
262
263                    $on
264		      ? $reflags |= $reflags{$_}
265		      : ($reflags &= ~$reflags{$_});
266		} else {
267		    require Carp;
268		    Carp::carp(
269		     qq'Unknown regular expression flag "$_"'
270		    );
271		    next ARG;
272		}
273	    }
274	    ($^H{reflags} = $reflags or defined $^H{reflags_charset})
275	                    ? $^H |= $flags_hint
276	                    : ($^H &= ~$flags_hint);
277	} else {
278	    require Carp;
279            if ($seen_debug && defined $flags{$s}) {
280                Carp::carp("Use \"Debug\" not \"debug\", to list debug types"
281                         . " in \"re\".  \"$s\" ignored");
282            }
283            else {
284                Carp::carp("Unknown \"re\" subpragma '$s' (known ones are: ",
285                       join(', ', map {qq('$_')} 'debug', 'debugcolor', sort keys %bitmask),
286                       ")");
287            }
288	}
289    }
290
291    if ($turning_all_off) {
292        _load_unload(0);
293        $^H{reflags} = 0;
294        $^H{reflags_charset} = 0;
295        $^H &= ~$flags_hint;
296    }
297
298    $bits;
299}
300
301sub import {
302    shift;
303    $^H |= bits(1, @_);
304}
305
306sub unimport {
307    shift;
308    $^H &= ~ bits(0, @_);
309}
310
3111;
312
313__END__
314
315=head1 NAME
316
317re - Perl pragma to alter regular expression behaviour
318
319=head1 SYNOPSIS
320
321    use re 'taint';
322    ($x) = ($^X =~ /^(.*)$/s);     # $x is tainted here
323
324    $pat = '(?{ $foo = 1 })';
325    use re 'eval';
326    /foo${pat}bar/;		   # won't fail (when not under -T
327                                   # switch)
328
329    {
330	no re 'taint';		   # the default
331	($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
332
333	no re 'eval';		   # the default
334	/foo${pat}bar/;		   # disallowed (with or without -T
335                                   # switch)
336    }
337
338    use re 'strict';               # Raise warnings for more conditions
339
340    use re '/ix';
341    "FOO" =~ / foo /; # /ix implied
342    no re '/x';
343    "FOO" =~ /foo/; # just /i implied
344
345    use re 'debug';		   # output debugging info during
346    /^(.*)$/s;			   # compile and run time
347
348
349    use re 'debugcolor';	   # same as 'debug', but with colored
350                                   # output
351    ...
352
353    use re qw(Debug All);          # Same as "use re 'debug'", but you
354                                   # can use "Debug" with things other
355                                   # than 'All'
356    use re qw(Debug More);         # 'All' plus output more details
357    no re qw(Debug ALL);           # Turn on (almost) all re debugging
358                                   # in this scope
359
360    use re qw(is_regexp regexp_pattern); # import utility functions
361    my ($pat,$mods)=regexp_pattern(qr/foo/i);
362    if (is_regexp($obj)) {
363        print "Got regexp: ",
364            scalar regexp_pattern($obj); # just as perl would stringify
365    }                                    # it but no hassle with blessed
366                                         # re's.
367
368(We use $^X in these examples because it's tainted by default.)
369
370=head1 DESCRIPTION
371
372=head2 'taint' mode
373
374When C<use re 'taint'> is in effect, and a tainted string is the target
375of a regexp, the regexp memories (or values returned by the m// operator
376in list context) are tainted.  This feature is useful when regexp operations
377on tainted data aren't meant to extract safe substrings, but to perform
378other transformations.
379
380=head2 'eval' mode
381
382When C<use re 'eval'> is in effect, a regexp is allowed to contain
383C<(?{ ... })> zero-width assertions and C<(??{ ... })> postponed
384subexpressions that are derived from variable interpolation, rather than
385appearing literally within the regexp.  That is normally disallowed, since
386it is a
387potential security risk.  Note that this pragma is ignored when the regular
388expression is obtained from tainted data, i.e.  evaluation is always
389disallowed with tainted regular expressions.  See L<perlre/(?{ code })>
390and L<perlre/(??{ code })>.
391
392For the purpose of this pragma, interpolation of precompiled regular
393expressions (i.e., the result of C<qr//>) is I<not> considered variable
394interpolation.  Thus:
395
396    /foo${pat}bar/
397
398I<is> allowed if $pat is a precompiled regular expression, even
399if $pat contains C<(?{ ... })> assertions or C<(??{ ... })> subexpressions.
400
401=head2 'strict' mode
402
403Note that this is an experimental feature which may be changed or removed in a
404future Perl release.
405
406When C<use re 'strict'> is in effect, stricter checks are applied than
407otherwise when compiling regular expressions patterns.  These may cause more
408warnings to be raised than otherwise, and more things to be fatal instead of
409just warnings.  The purpose of this is to find and report at compile time some
410things, which may be legal, but have a reasonable possibility of not being the
411programmer's actual intent.  This automatically turns on the C<"regexp">
412warnings category (if not already on) within its scope.
413
414As an example of something that is caught under C<"strict'>, but not
415otherwise, is the pattern
416
417 qr/\xABC/
418
419The C<"\x"> construct without curly braces should be followed by exactly two
420hex digits; this one is followed by three.  This currently evaluates as
421equivalent to
422
423 qr/\x{AB}C/
424
425that is, the character whose code point value is C<0xAB>, followed by the
426letter C<C>.  But since C<C> is a hex digit, there is a reasonable chance
427that the intent was
428
429 qr/\x{ABC}/
430
431that is the single character at C<0xABC>.  Under C<'strict'> it is an error to
432not follow C<\x> with exactly two hex digits.  When not under C<'strict'> a
433warning is generated if there is only one hex digit, and no warning is raised
434if there are more than two.
435
436It is expected that what exactly C<'strict'> does will evolve over time as we
437gain experience with it.  This means that programs that compile under it in
438today's Perl may not compile, or may have more or fewer warnings, in future
439Perls.  There is no backwards compatibility promises with regards to it.  Also
440there are already proposals for an alternate syntax for enabling it.  For
441these reasons, using it will raise a C<experimental::re_strict> class warning,
442unless that category is turned off.
443
444Note that if a pattern compiled within C<'strict'> is recompiled, say by
445interpolating into another pattern, outside of C<'strict'>, it is not checked
446again for strictness.  This is because if it works under strict it must work
447under non-strict.
448
449=head2 '/flags' mode
450
451When C<use re '/I<flags>'> is specified, the given I<flags> are automatically
452added to every regular expression till the end of the lexical scope.
453I<flags> can be any combination of
454C<'a'>,
455C<'aa'>,
456C<'d'>,
457C<'i'>,
458C<'l'>,
459C<'m'>,
460C<'n'>,
461C<'p'>,
462C<'s'>,
463C<'u'>,
464C<'x'>,
465and/or
466C<'xx'>.
467
468C<no re '/I<flags>'> will turn off the effect of C<use re '/I<flags>'> for the
469given flags.
470
471For example, if you want all your regular expressions to have /msxx on by
472default, simply put
473
474    use re '/msxx';
475
476at the top of your code.
477
478The character set C</adul> flags cancel each other out. So, in this example,
479
480    use re "/u";
481    "ss" =~ /\xdf/;
482    use re "/d";
483    "ss" =~ /\xdf/;
484
485the second C<use re> does an implicit C<no re '/u'>.
486
487Similarly,
488
489    use re "/xx";   # Doubled-x
490    ...
491    use re "/x";    # Single x from here on
492    ...
493
494Turning on one of the character set flags with C<use re> takes precedence over the
495C<locale> pragma and the 'unicode_strings' C<feature>, for regular
496expressions. Turning off one of these flags when it is active reverts to
497the behaviour specified by whatever other pragmata are in scope. For
498example:
499
500    use feature "unicode_strings";
501    no re "/u"; # does nothing
502    use re "/l";
503    no re "/l"; # reverts to unicode_strings behaviour
504
505=head2 'debug' mode
506
507When C<use re 'debug'> is in effect, perl emits debugging messages when
508compiling and using regular expressions.  The output is the same as that
509obtained by running a C<-DDEBUGGING>-enabled perl interpreter with the
510B<-Dr> switch. It may be quite voluminous depending on the complexity
511of the match.  Using C<debugcolor> instead of C<debug> enables a
512form of output that can be used to get a colorful display on terminals
513that understand termcap color sequences.  Set C<$ENV{PERL_RE_TC}> to a
514comma-separated list of C<termcap> properties to use for highlighting
515strings on/off, pre-point part on/off.
516See L<perldebug/"Debugging Regular Expressions"> for additional info.
517
518As of 5.9.5 the directive C<use re 'debug'> and its equivalents are
519lexically scoped, as the other directives are.  However they have both
520compile-time and run-time effects.
521
522See L<perlmodlib/Pragmatic Modules>.
523
524=head2 'Debug' mode
525
526Similarly C<use re 'Debug'> produces debugging output, the difference
527being that it allows the fine tuning of what debugging output will be
528emitted. Options are divided into three groups, those related to
529compilation, those related to execution and those related to special
530purposes. The options are as follows:
531
532=over 4
533
534=item Compile related options
535
536=over 4
537
538=item COMPILE
539
540Turns on all non-extra compile related debug options.
541
542=item PARSE
543
544Turns on debug output related to the process of parsing the pattern.
545
546=item OPTIMISE
547
548Enables output related to the optimisation phase of compilation.
549
550=item TRIEC
551
552Detailed info about trie compilation.
553
554=item DUMP
555
556Dump the final program out after it is compiled and optimised.
557
558=item FLAGS
559
560Dump the flags associated with the program
561
562=item TEST
563
564Print output intended for testing the internals of the compile process
565
566=back
567
568=item Execute related options
569
570=over 4
571
572=item EXECUTE
573
574Turns on all non-extra execute related debug options.
575
576=item MATCH
577
578Turns on debugging of the main matching loop.
579
580=item TRIEE
581
582Extra debugging of how tries execute.
583
584=item INTUIT
585
586Enable debugging of start-point optimisations.
587
588=back
589
590=item Extra debugging options
591
592=over 4
593
594=item EXTRA
595
596Turns on all "extra" debugging options.
597
598=item BUFFERS
599
600Enable debugging the capture group storage during match. Warning,
601this can potentially produce extremely large output.
602
603=item TRIEM
604
605Enable enhanced TRIE debugging. Enhances both TRIEE
606and TRIEC.
607
608=item STATE
609
610Enable debugging of states in the engine.
611
612=item STACK
613
614Enable debugging of the recursion stack in the engine. Enabling
615or disabling this option automatically does the same for debugging
616states as well. This output from this can be quite large.
617
618=item GPOS
619
620Enable debugging of the \G modifier.
621
622=item OPTIMISEM
623
624Enable enhanced optimisation debugging and start-point optimisations.
625Probably not useful except when debugging the regexp engine itself.
626
627=item OFFSETS
628
629Dump offset information. This can be used to see how regops correlate
630to the pattern. Output format is
631
632   NODENUM:POSITION[LENGTH]
633
634Where 1 is the position of the first char in the string. Note that position
635can be 0, or larger than the actual length of the pattern, likewise length
636can be zero.
637
638=item OFFSETSDBG
639
640Enable debugging of offsets information. This emits copious
641amounts of trace information and doesn't mesh well with other
642debug options.
643
644Almost definitely only useful to people hacking
645on the offsets part of the debug engine.
646
647=item DUMP_PRE_OPTIMIZE
648
649Enable the dumping of the compiled pattern before the optimization phase.
650
651=item WILDCARD
652
653When Perl encounters a wildcard subpattern, (see L<perlunicode/Wildcards in
654Property Values>), it suspends compilation of the main pattern, compiles the
655subpattern, and then matches that against all legal possibilities to determine
656the actual code points the subpattern matches.  After that it adds these to
657the main pattern, and continues its compilation.
658
659You may very well want to see how your subpattern gets compiled, but it is
660likely of less use to you to see how Perl matches that against all the legal
661possibilities, as that is under control of Perl, not you.   Therefore, the
662debugging information of the compilation portion is as specified by the other
663options, but the debugging output of the matching portion is normally
664suppressed.
665
666You can use the WILDCARD option to enable the debugging output of this
667subpattern matching.  Careful!  This can lead to voluminous outputs, and it
668may not make much sense to you what and why Perl is doing what it is.
669But it may be helpful to you to see why things aren't going the way you
670expect.
671
672Note that this option alone doesn't cause any debugging information to be
673output.  What it does is stop the normal suppression of execution-related
674debugging information during the matching portion of the compilation of
675wildcards.  You also have to specify which execution debugging information you
676want, such as by also including the EXECUTE option.
677
678=back
679
680=item Other useful flags
681
682These are useful shortcuts to save on the typing.
683
684=over 4
685
686=item ALL
687
688Enable all options at once except OFFSETS, OFFSETSDBG, BUFFERS, WILDCARD, and
689DUMP_PRE_OPTIMIZE.
690(To get every single option without exception, use both ALL and EXTRA, or
691starting in 5.30 on a C<-DDEBUGGING>-enabled perl interpreter, use
692the B<-Drv> command-line switches.)
693
694=item All
695
696Enable DUMP and all non-extra execute options. Equivalent to:
697
698  use re 'debug';
699
700=item MORE
701
702=item More
703
704Enable the options enabled by "All", plus STATE, TRIEC, and TRIEM.
705
706=back
707
708=back
709
710As of 5.9.5 the directive C<use re 'debug'> and its equivalents are
711lexically scoped, as are the other directives.  However they have both
712compile-time and run-time effects.
713
714=head2 Exportable Functions
715
716As of perl 5.9.5 're' debug contains a number of utility functions that
717may be optionally exported into the caller's namespace. They are listed
718below.
719
720=over 4
721
722=item is_regexp($ref)
723
724Returns true if the argument is a compiled regular expression as returned
725by C<qr//>, false if it is not.
726
727This function will not be confused by overloading or blessing. In
728internals terms, this extracts the regexp pointer out of the
729PERL_MAGIC_qr structure so it cannot be fooled.
730
731=item regexp_pattern($ref)
732
733If the argument is a compiled regular expression as returned by C<qr//>,
734then this function returns the pattern.
735
736In list context it returns a two element list, the first element
737containing the pattern and the second containing the modifiers used when
738the pattern was compiled.
739
740  my ($pat, $mods) = regexp_pattern($ref);
741
742In scalar context it returns the same as perl would when stringifying a raw
743C<qr//> with the same pattern inside.  If the argument is not a compiled
744reference then this routine returns false but defined in scalar context,
745and the empty list in list context. Thus the following
746
747    if (regexp_pattern($ref) eq '(?^i:foo)')
748
749will be warning free regardless of what $ref actually is.
750
751Like C<is_regexp> this function will not be confused by overloading
752or blessing of the object.
753
754=item regmust($ref)
755
756If the argument is a compiled regular expression as returned by C<qr//>,
757then this function returns what the optimiser considers to be the longest
758anchored fixed string and longest floating fixed string in the pattern.
759
760A I<fixed string> is defined as being a substring that must appear for the
761pattern to match. An I<anchored fixed string> is a fixed string that must
762appear at a particular offset from the beginning of the match. A I<floating
763fixed string> is defined as a fixed string that can appear at any point in
764a range of positions relative to the start of the match. For example,
765
766    my $qr = qr/here .* there/x;
767    my ($anchored, $floating) = regmust($qr);
768    print "anchored:'$anchored'\nfloating:'$floating'\n";
769
770results in
771
772    anchored:'here'
773    floating:'there'
774
775Because the C<here> is before the C<.*> in the pattern, its position
776can be determined exactly. That's not true, however, for the C<there>;
777it could appear at any point after where the anchored string appeared.
778Perl uses both for its optimisations, preferring the longer, or, if they are
779equal, the floating.
780
781B<NOTE:> This may not necessarily be the definitive longest anchored and
782floating string. This will be what the optimiser of the Perl that you
783are using thinks is the longest. If you believe that the result is wrong
784please report it via the L<perlbug> utility.
785
786=item regname($name,$all)
787
788Returns the contents of a named buffer of the last successful match. If
789$all is true, then returns an array ref containing one entry per buffer,
790otherwise returns the first defined buffer.
791
792=item regnames($all)
793
794Returns a list of all of the named buffers defined in the last successful
795match. If $all is true, then it returns all names defined, if not it returns
796only names which were involved in the match.
797
798=item regnames_count()
799
800Returns the number of distinct names defined in the pattern used
801for the last successful match.
802
803B<Note:> this result is always the actual number of distinct
804named buffers defined, it may not actually match that which is
805returned by C<regnames()> and related routines when those routines
806have not been called with the $all parameter set.
807
808=back
809
810=head1 SEE ALSO
811
812L<perlmodlib/Pragmatic Modules>.
813
814=cut
815