re.pm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. package re;
  2. # pragma for controlling the regexp engine
  3. use strict;
  4. use warnings;
  5. our $VERSION = "0.32";
  6. our @ISA = qw(Exporter);
  7. our @EXPORT_OK = ('regmust',
  8. qw(is_regexp regexp_pattern
  9. regname regnames regnames_count));
  10. our %EXPORT_OK = map { $_ => 1 } @EXPORT_OK;
  11. my %bitmask = (
  12. taint => 0x00100000, # HINT_RE_TAINT
  13. eval => 0x00200000, # HINT_RE_EVAL
  14. );
  15. my $flags_hint = 0x02000000; # HINT_RE_FLAGS
  16. my $PMMOD_SHIFT = 0;
  17. my %reflags = (
  18. m => 1 << ($PMMOD_SHIFT + 0),
  19. s => 1 << ($PMMOD_SHIFT + 1),
  20. i => 1 << ($PMMOD_SHIFT + 2),
  21. x => 1 << ($PMMOD_SHIFT + 3),
  22. n => 1 << ($PMMOD_SHIFT + 5),
  23. p => 1 << ($PMMOD_SHIFT + 6),
  24. strict => 1 << ($PMMOD_SHIFT + 10),
  25. # special cases:
  26. d => 0,
  27. l => 1,
  28. u => 2,
  29. a => 3,
  30. aa => 4,
  31. );
  32. sub setcolor {
  33. eval { # Ignore errors
  34. require Term::Cap;
  35. my $terminal = Tgetent Term::Cap ({OSPEED => 9600}); # Avoid warning.
  36. my $props = $ENV{PERL_RE_TC} || 'md,me,so,se,us,ue';
  37. my @props = split /,/, $props;
  38. my $colors = join "\t", map {$terminal->Tputs($_,1)} @props;
  39. $colors =~ s/\0//g;
  40. $ENV{PERL_RE_COLORS} = $colors;
  41. };
  42. if ($@) {
  43. $ENV{PERL_RE_COLORS} ||= qq'\t\t> <\t> <\t\t';
  44. }
  45. }
  46. my %flags = (
  47. COMPILE => 0x0000FF,
  48. PARSE => 0x000001,
  49. OPTIMISE => 0x000002,
  50. TRIEC => 0x000004,
  51. DUMP => 0x000008,
  52. FLAGS => 0x000010,
  53. TEST => 0x000020,
  54. EXECUTE => 0x00FF00,
  55. INTUIT => 0x000100,
  56. MATCH => 0x000200,
  57. TRIEE => 0x000400,
  58. EXTRA => 0xFF0000,
  59. TRIEM => 0x010000,
  60. OFFSETS => 0x020000,
  61. OFFSETSDBG => 0x040000,
  62. STATE => 0x080000,
  63. OPTIMISEM => 0x100000,
  64. STACK => 0x280000,
  65. BUFFERS => 0x400000,
  66. GPOS => 0x800000,
  67. );
  68. $flags{ALL} = -1 & ~($flags{OFFSETS}|$flags{OFFSETSDBG}|$flags{BUFFERS});
  69. $flags{All} = $flags{all} = $flags{DUMP} | $flags{EXECUTE};
  70. $flags{Extra} = $flags{EXECUTE} | $flags{COMPILE} | $flags{GPOS};
  71. $flags{More} = $flags{MORE} = $flags{All} | $flags{TRIEC} | $flags{TRIEM} | $flags{STATE};
  72. $flags{State} = $flags{DUMP} | $flags{EXECUTE} | $flags{STATE};
  73. $flags{TRIE} = $flags{DUMP} | $flags{EXECUTE} | $flags{TRIEC};
  74. if (defined &DynaLoader::boot_DynaLoader) {
  75. require XSLoader;
  76. XSLoader::load();
  77. }
  78. # else we're miniperl
  79. # We need to work for miniperl, because the XS toolchain uses Text::Wrap, which
  80. # uses re 'taint'.
  81. sub _load_unload {
  82. my ($on)= @_;
  83. if ($on) {
  84. # We call install() every time, as if we didn't, we wouldn't
  85. # "see" any changes to the color environment var since
  86. # the last time it was called.
  87. # install() returns an integer, which if casted properly
  88. # in C resolves to a structure containing the regexp
  89. # hooks. Setting it to a random integer will guarantee
  90. # segfaults.
  91. $^H{regcomp} = install();
  92. } else {
  93. delete $^H{regcomp};
  94. }
  95. }
  96. sub bits {
  97. my $on = shift;
  98. my $bits = 0;
  99. my $turning_all_off = ! @_ && ! $on;
  100. my %seen; # Has flag already been seen?
  101. if ($turning_all_off) {
  102. # Pretend were called with certain parameters, which are best dealt
  103. # with that way.
  104. push @_, keys %bitmask; # taint and eval
  105. push @_, 'strict';
  106. }
  107. # Process each subpragma parameter
  108. ARG:
  109. foreach my $idx (0..$#_){
  110. my $s=$_[$idx];
  111. if ($s eq 'Debug' or $s eq 'Debugcolor') {
  112. setcolor() if $s =~/color/i;
  113. ${^RE_DEBUG_FLAGS} = 0 unless defined ${^RE_DEBUG_FLAGS};
  114. for my $idx ($idx+1..$#_) {
  115. if ($flags{$_[$idx]}) {
  116. if ($on) {
  117. ${^RE_DEBUG_FLAGS} |= $flags{$_[$idx]};
  118. } else {
  119. ${^RE_DEBUG_FLAGS} &= ~ $flags{$_[$idx]};
  120. }
  121. } else {
  122. require Carp;
  123. Carp::carp("Unknown \"re\" Debug flag '$_[$idx]', possible flags: ",
  124. join(", ",sort keys %flags ) );
  125. }
  126. }
  127. _load_unload($on ? 1 : ${^RE_DEBUG_FLAGS});
  128. last;
  129. } elsif ($s eq 'debug' or $s eq 'debugcolor') {
  130. setcolor() if $s =~/color/i;
  131. _load_unload($on);
  132. last;
  133. } elsif (exists $bitmask{$s}) {
  134. $bits |= $bitmask{$s};
  135. } elsif ($EXPORT_OK{$s}) {
  136. require Exporter;
  137. re->export_to_level(2, 're', $s);
  138. } elsif ($s eq 'strict') {
  139. if ($on) {
  140. $^H{reflags} |= $reflags{$s};
  141. warnings::warnif('experimental::re_strict',
  142. "\"use re 'strict'\" is experimental");
  143. # Turn on warnings if not already done.
  144. if (! warnings::enabled('regexp')) {
  145. require warnings;
  146. warnings->import('regexp');
  147. $^H{re_strict} = 1;
  148. }
  149. }
  150. else {
  151. $^H{reflags} &= ~$reflags{$s} if $^H{reflags};
  152. # Turn off warnings if we turned them on.
  153. warnings->unimport('regexp') if $^H{re_strict};
  154. }
  155. if ($^H{reflags}) {
  156. $^H |= $flags_hint;
  157. }
  158. else {
  159. $^H &= ~$flags_hint;
  160. }
  161. } elsif ($s =~ s/^\///) {
  162. my $reflags = $^H{reflags} || 0;
  163. my $seen_charset;
  164. while ($s =~ m/( . )/gx) {
  165. local $_ = $1;
  166. if (/[adul]/) {
  167. # The 'a' may be repeated; hide this from the rest of the
  168. # code by counting and getting rid of all of them, then
  169. # changing to 'aa' if there is a repeat.
  170. if ($_ eq 'a') {
  171. my $sav_pos = pos $s;
  172. my $a_count = $s =~ s/a//g;
  173. pos $s = $sav_pos - 1; # -1 because got rid of the 'a'
  174. if ($a_count > 2) {
  175. require Carp;
  176. Carp::carp(
  177. qq 'The "a" flag may only appear a maximum of twice'
  178. );
  179. }
  180. elsif ($a_count == 2) {
  181. $_ = 'aa';
  182. }
  183. }
  184. if ($on) {
  185. if ($seen_charset) {
  186. require Carp;
  187. if ($seen_charset ne $_) {
  188. Carp::carp(
  189. qq 'The "$seen_charset" and "$_" flags '
  190. .qq 'are exclusive'
  191. );
  192. }
  193. else {
  194. Carp::carp(
  195. qq 'The "$seen_charset" flag may not appear '
  196. .qq 'twice'
  197. );
  198. }
  199. }
  200. $^H{reflags_charset} = $reflags{$_};
  201. $seen_charset = $_;
  202. }
  203. else {
  204. delete $^H{reflags_charset}
  205. if defined $^H{reflags_charset}
  206. && $^H{reflags_charset} == $reflags{$_};
  207. }
  208. } elsif (exists $reflags{$_}) {
  209. $seen{$_}++;
  210. $on
  211. ? $reflags |= $reflags{$_}
  212. : ($reflags &= ~$reflags{$_});
  213. } else {
  214. require Carp;
  215. Carp::carp(
  216. qq'Unknown regular expression flag "$_"'
  217. );
  218. next ARG;
  219. }
  220. }
  221. ($^H{reflags} = $reflags or defined $^H{reflags_charset})
  222. ? $^H |= $flags_hint
  223. : ($^H &= ~$flags_hint);
  224. } else {
  225. require Carp;
  226. Carp::carp("Unknown \"re\" subpragma '$s' (known ones are: ",
  227. join(', ', map {qq('$_')} 'debug', 'debugcolor', sort keys %bitmask),
  228. ")");
  229. }
  230. }
  231. if (exists $seen{'x'} && $seen{'x'} > 1
  232. && (warnings::enabled("deprecated")
  233. || warnings::enabled("regexp")))
  234. {
  235. my $message = "Having more than one /x regexp modifier is deprecated";
  236. if (warnings::enabled("deprecated")) {
  237. warnings::warn("deprecated", $message);
  238. }
  239. else {
  240. warnings::warn("regexp", $message);
  241. }
  242. }
  243. if ($turning_all_off) {
  244. _load_unload(0);
  245. $^H{reflags} = 0;
  246. $^H{reflags_charset} = 0;
  247. $^H &= ~$flags_hint;
  248. }
  249. $bits;
  250. }
  251. sub import {
  252. shift;
  253. $^H |= bits(1, @_);
  254. }
  255. sub unimport {
  256. shift;
  257. $^H &= ~ bits(0, @_);
  258. }
  259. 1;
  260. __END__
  261. =head1 NAME
  262. re - Perl pragma to alter regular expression behaviour
  263. =head1 SYNOPSIS
  264. use re 'taint';
  265. ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here
  266. $pat = '(?{ $foo = 1 })';
  267. use re 'eval';
  268. /foo${pat}bar/; # won't fail (when not under -T
  269. # switch)
  270. {
  271. no re 'taint'; # the default
  272. ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
  273. no re 'eval'; # the default
  274. /foo${pat}bar/; # disallowed (with or without -T
  275. # switch)
  276. }
  277. use re 'strict'; # Raise warnings for more conditions
  278. use re '/ix';
  279. "FOO" =~ / foo /; # /ix implied
  280. no re '/x';
  281. "FOO" =~ /foo/; # just /i implied
  282. use re 'debug'; # output debugging info during
  283. /^(.*)$/s; # compile and run time
  284. use re 'debugcolor'; # same as 'debug', but with colored
  285. # output
  286. ...
  287. use re qw(Debug All); # Same as "use re 'debug'", but you
  288. # can use "Debug" with things other
  289. # than 'All'
  290. use re qw(Debug More); # 'All' plus output more details
  291. no re qw(Debug ALL); # Turn on (almost) all re debugging
  292. # in this scope
  293. use re qw(is_regexp regexp_pattern); # import utility functions
  294. my ($pat,$mods)=regexp_pattern(qr/foo/i);
  295. if (is_regexp($obj)) {
  296. print "Got regexp: ",
  297. scalar regexp_pattern($obj); # just as perl would stringify
  298. } # it but no hassle with blessed
  299. # re's.
  300. (We use $^X in these examples because it's tainted by default.)
  301. =head1 DESCRIPTION
  302. =head2 'taint' mode
  303. When C<use re 'taint'> is in effect, and a tainted string is the target
  304. of a regexp, the regexp memories (or values returned by the m// operator
  305. in list context) are tainted. This feature is useful when regexp operations
  306. on tainted data aren't meant to extract safe substrings, but to perform
  307. other transformations.
  308. =head2 'eval' mode
  309. When C<use re 'eval'> is in effect, a regexp is allowed to contain
  310. C<(?{ ... })> zero-width assertions and C<(??{ ... })> postponed
  311. subexpressions that are derived from variable interpolation, rather than
  312. appearing literally within the regexp. That is normally disallowed, since
  313. it is a
  314. potential security risk. Note that this pragma is ignored when the regular
  315. expression is obtained from tainted data, i.e. evaluation is always
  316. disallowed with tainted regular expressions. See L<perlre/(?{ code })>
  317. and L<perlre/(??{ code })>.
  318. For the purpose of this pragma, interpolation of precompiled regular
  319. expressions (i.e., the result of C<qr//>) is I<not> considered variable
  320. interpolation. Thus:
  321. /foo${pat}bar/
  322. I<is> allowed if $pat is a precompiled regular expression, even
  323. if $pat contains C<(?{ ... })> assertions or C<(??{ ... })> subexpressions.
  324. =head2 'strict' mode
  325. Note that this is an experimental feature which may be changed or removed in a
  326. future Perl release.
  327. When C<use re 'strict'> is in effect, stricter checks are applied than
  328. otherwise when compiling regular expressions patterns. These may cause more
  329. warnings to be raised than otherwise, and more things to be fatal instead of
  330. just warnings. The purpose of this is to find and report at compile time some
  331. things, which may be legal, but have a reasonable possibility of not being the
  332. programmer's actual intent. This automatically turns on the C<"regexp">
  333. warnings category (if not already on) within its scope.
  334. As an example of something that is caught under C<"strict'>, but not
  335. otherwise, is the pattern
  336. qr/\xABC/
  337. The C<"\x"> construct without curly braces should be followed by exactly two
  338. hex digits; this one is followed by three. This currently evaluates as
  339. equivalent to
  340. qr/\x{AB}C/
  341. that is, the character whose code point value is C<0xAB>, followed by the
  342. letter C<C>. But since C<C> is a a hex digit, there is a reasonable chance
  343. that the intent was
  344. qr/\x{ABC}/
  345. that is the single character at C<0xABC>. Under C<'strict'> it is an error to
  346. not follow C<\x> with exactly two hex digits. When not under C<'strict'> a
  347. warning is generated if there is only one hex digit, and no warning is raised
  348. if there are more than two.
  349. It is expected that what exactly C<'strict'> does will evolve over time as we
  350. gain experience with it. This means that programs that compile under it in
  351. today's Perl may not compile, or may have more or fewer warnings, in future
  352. Perls. There is no backwards compatibility promises with regards to it. Also
  353. there are already proposals for an alternate syntax for enabling it. For
  354. these reasons, using it will raise a C<experimental::re_strict> class warning,
  355. unless that category is turned off.
  356. Note that if a pattern compiled within C<'strict'> is recompiled, say by
  357. interpolating into another pattern, outside of C<'strict'>, it is not checked
  358. again for strictness. This is because if it works under strict it must work
  359. under non-strict.
  360. =head2 '/flags' mode
  361. When C<use re '/flags'> is specified, the given flags are automatically
  362. added to every regular expression till the end of the lexical scope.
  363. C<no re '/flags'> will turn off the effect of C<use re '/flags'> for the
  364. given flags.
  365. For example, if you want all your regular expressions to have /msx on by
  366. default, simply put
  367. use re '/msx';
  368. at the top of your code.
  369. The character set /adul flags cancel each other out. So, in this example,
  370. use re "/u";
  371. "ss" =~ /\xdf/;
  372. use re "/d";
  373. "ss" =~ /\xdf/;
  374. the second C<use re> does an implicit C<no re '/u'>.
  375. Turning on one of the character set flags with C<use re> takes precedence over the
  376. C<locale> pragma and the 'unicode_strings' C<feature>, for regular
  377. expressions. Turning off one of these flags when it is active reverts to
  378. the behaviour specified by whatever other pragmata are in scope. For
  379. example:
  380. use feature "unicode_strings";
  381. no re "/u"; # does nothing
  382. use re "/l";
  383. no re "/l"; # reverts to unicode_strings behaviour
  384. =head2 'debug' mode
  385. When C<use re 'debug'> is in effect, perl emits debugging messages when
  386. compiling and using regular expressions. The output is the same as that
  387. obtained by running a C<-DDEBUGGING>-enabled perl interpreter with the
  388. B<-Dr> switch. It may be quite voluminous depending on the complexity
  389. of the match. Using C<debugcolor> instead of C<debug> enables a
  390. form of output that can be used to get a colorful display on terminals
  391. that understand termcap color sequences. Set C<$ENV{PERL_RE_TC}> to a
  392. comma-separated list of C<termcap> properties to use for highlighting
  393. strings on/off, pre-point part on/off.
  394. See L<perldebug/"Debugging Regular Expressions"> for additional info.
  395. As of 5.9.5 the directive C<use re 'debug'> and its equivalents are
  396. lexically scoped, as the other directives are. However they have both
  397. compile-time and run-time effects.
  398. See L<perlmodlib/Pragmatic Modules>.
  399. =head2 'Debug' mode
  400. Similarly C<use re 'Debug'> produces debugging output, the difference
  401. being that it allows the fine tuning of what debugging output will be
  402. emitted. Options are divided into three groups, those related to
  403. compilation, those related to execution and those related to special
  404. purposes. The options are as follows:
  405. =over 4
  406. =item Compile related options
  407. =over 4
  408. =item COMPILE
  409. Turns on all compile related debug options.
  410. =item PARSE
  411. Turns on debug output related to the process of parsing the pattern.
  412. =item OPTIMISE
  413. Enables output related to the optimisation phase of compilation.
  414. =item TRIEC
  415. Detailed info about trie compilation.
  416. =item DUMP
  417. Dump the final program out after it is compiled and optimised.
  418. =item FLAGS
  419. Dump the flags associated with the program
  420. =item TEST
  421. Print output intended for testing the internals of the compile process
  422. =back
  423. =item Execute related options
  424. =over 4
  425. =item EXECUTE
  426. Turns on all execute related debug options.
  427. =item MATCH
  428. Turns on debugging of the main matching loop.
  429. =item TRIEE
  430. Extra debugging of how tries execute.
  431. =item INTUIT
  432. Enable debugging of start-point optimisations.
  433. =back
  434. =item Extra debugging options
  435. =over 4
  436. =item EXTRA
  437. Turns on all "extra" debugging options.
  438. =item BUFFERS
  439. Enable debugging the capture group storage during match. Warning,
  440. this can potentially produce extremely large output.
  441. =item TRIEM
  442. Enable enhanced TRIE debugging. Enhances both TRIEE
  443. and TRIEC.
  444. =item STATE
  445. Enable debugging of states in the engine.
  446. =item STACK
  447. Enable debugging of the recursion stack in the engine. Enabling
  448. or disabling this option automatically does the same for debugging
  449. states as well. This output from this can be quite large.
  450. =item GPOS
  451. Enable debugging of the \G modifier.
  452. =item OPTIMISEM
  453. Enable enhanced optimisation debugging and start-point optimisations.
  454. Probably not useful except when debugging the regexp engine itself.
  455. =item OFFSETS
  456. Dump offset information. This can be used to see how regops correlate
  457. to the pattern. Output format is
  458. NODENUM:POSITION[LENGTH]
  459. Where 1 is the position of the first char in the string. Note that position
  460. can be 0, or larger than the actual length of the pattern, likewise length
  461. can be zero.
  462. =item OFFSETSDBG
  463. Enable debugging of offsets information. This emits copious
  464. amounts of trace information and doesn't mesh well with other
  465. debug options.
  466. Almost definitely only useful to people hacking
  467. on the offsets part of the debug engine.
  468. =back
  469. =item Other useful flags
  470. These are useful shortcuts to save on the typing.
  471. =over 4
  472. =item ALL
  473. Enable all options at once except OFFSETS, OFFSETSDBG and BUFFERS.
  474. (To get every single option without exception, use both ALL and EXTRA.)
  475. =item All
  476. Enable DUMP and all execute options. Equivalent to:
  477. use re 'debug';
  478. =item MORE
  479. =item More
  480. Enable the options enabled by "All", plus STATE, TRIEC, and TRIEM.
  481. =back
  482. =back
  483. As of 5.9.5 the directive C<use re 'debug'> and its equivalents are
  484. lexically scoped, as are the other directives. However they have both
  485. compile-time and run-time effects.
  486. =head2 Exportable Functions
  487. As of perl 5.9.5 're' debug contains a number of utility functions that
  488. may be optionally exported into the caller's namespace. They are listed
  489. below.
  490. =over 4
  491. =item is_regexp($ref)
  492. Returns true if the argument is a compiled regular expression as returned
  493. by C<qr//>, false if it is not.
  494. This function will not be confused by overloading or blessing. In
  495. internals terms, this extracts the regexp pointer out of the
  496. PERL_MAGIC_qr structure so it cannot be fooled.
  497. =item regexp_pattern($ref)
  498. If the argument is a compiled regular expression as returned by C<qr//>,
  499. then this function returns the pattern.
  500. In list context it returns a two element list, the first element
  501. containing the pattern and the second containing the modifiers used when
  502. the pattern was compiled.
  503. my ($pat, $mods) = regexp_pattern($ref);
  504. In scalar context it returns the same as perl would when stringifying a raw
  505. C<qr//> with the same pattern inside. If the argument is not a compiled
  506. reference then this routine returns false but defined in scalar context,
  507. and the empty list in list context. Thus the following
  508. if (regexp_pattern($ref) eq '(?^i:foo)')
  509. will be warning free regardless of what $ref actually is.
  510. Like C<is_regexp> this function will not be confused by overloading
  511. or blessing of the object.
  512. =item regmust($ref)
  513. If the argument is a compiled regular expression as returned by C<qr//>,
  514. then this function returns what the optimiser considers to be the longest
  515. anchored fixed string and longest floating fixed string in the pattern.
  516. A I<fixed string> is defined as being a substring that must appear for the
  517. pattern to match. An I<anchored fixed string> is a fixed string that must
  518. appear at a particular offset from the beginning of the match. A I<floating
  519. fixed string> is defined as a fixed string that can appear at any point in
  520. a range of positions relative to the start of the match. For example,
  521. my $qr = qr/here .* there/x;
  522. my ($anchored, $floating) = regmust($qr);
  523. print "anchored:'$anchored'\nfloating:'$floating'\n";
  524. results in
  525. anchored:'here'
  526. floating:'there'
  527. Because the C<here> is before the C<.*> in the pattern, its position
  528. can be determined exactly. That's not true, however, for the C<there>;
  529. it could appear at any point after where the anchored string appeared.
  530. Perl uses both for its optimisations, preferring the longer, or, if they are
  531. equal, the floating.
  532. B<NOTE:> This may not necessarily be the definitive longest anchored and
  533. floating string. This will be what the optimiser of the Perl that you
  534. are using thinks is the longest. If you believe that the result is wrong
  535. please report it via the L<perlbug> utility.
  536. =item regname($name,$all)
  537. Returns the contents of a named buffer of the last successful match. If
  538. $all is true, then returns an array ref containing one entry per buffer,
  539. otherwise returns the first defined buffer.
  540. =item regnames($all)
  541. Returns a list of all of the named buffers defined in the last successful
  542. match. If $all is true, then it returns all names defined, if not it returns
  543. only names which were involved in the match.
  544. =item regnames_count()
  545. Returns the number of distinct names defined in the pattern used
  546. for the last successful match.
  547. B<Note:> this result is always the actual number of distinct
  548. named buffers defined, it may not actually match that which is
  549. returned by C<regnames()> and related routines when those routines
  550. have not been called with the $all parameter set.
  551. =back
  552. =head1 SEE ALSO
  553. L<perlmodlib/Pragmatic Modules>.
  554. =cut