{
    "content": [
        {
            "type": "text",
            "text": "# re (man)\n\n## NAME\n\nre - Perl pragma to alter regular expression behaviour\n\n## SYNOPSIS\n\nuse re 'taint';\n($x) = ($^X =~ /^(.*)$/s);     # $x is tainted here\n$pat = '(?{ $foo = 1 })';\nuse re 'eval';\n/foo${pat}bar/;                # won't fail (when not under -T\n# switch)\n{\nno re 'taint';             # the default\n($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here\nno re 'eval';              # the default\n/foo${pat}bar/;            # disallowed (with or without -T\n# switch)\n}\nuse re 'strict';               # Raise warnings for more conditions\nuse re '/ix';\n\"FOO\" =~ / foo /; # /ix implied\nno re '/x';\n\"FOO\" =~ /foo/; # just /i implied\nuse re 'debug';                # output debugging info during\n/^(.*)$/s;                     # compile and run time\nuse re 'debugcolor';           # same as 'debug', but with colored\n# output\n...\nuse re qw(Debug All);          # Same as \"use re 'debug'\", but you\n# can use \"Debug\" with things other\n# than 'All'\nuse re qw(Debug More);         # 'All' plus output more details\nno re qw(Debug ALL);           # Turn on (almost) all re debugging\n# in this scope\nuse re qw(isregexp regexppattern); # import utility functions\nmy ($pat,$mods)=regexppattern(qr/foo/i);\nif (isregexp($obj)) {\nprint \"Got regexp: \",\nscalar regexppattern($obj); # just as perl would stringify\n}                                    # it but no hassle with blessed\n# re's.\n(We use $^X in these examples because it's tainted by default.)\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (7 subsections)\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "re",
        "section": "",
        "mode": "man",
        "summary": "re - Perl pragma to alter regular expression behaviour",
        "synopsis": "use re 'taint';\n($x) = ($^X =~ /^(.*)$/s);     # $x is tainted here\n$pat = '(?{ $foo = 1 })';\nuse re 'eval';\n/foo${pat}bar/;                # won't fail (when not under -T\n# switch)\n{\nno re 'taint';             # the default\n($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here\nno re 'eval';              # the default\n/foo${pat}bar/;            # disallowed (with or without -T\n# switch)\n}\nuse re 'strict';               # Raise warnings for more conditions\nuse re '/ix';\n\"FOO\" =~ / foo /; # /ix implied\nno re '/x';\n\"FOO\" =~ /foo/; # just /i implied\nuse re 'debug';                # output debugging info during\n/^(.*)$/s;                     # compile and run time\nuse re 'debugcolor';           # same as 'debug', but with colored\n# output\n...\nuse re qw(Debug All);          # Same as \"use re 'debug'\", but you\n# can use \"Debug\" with things other\n# than 'All'\nuse re qw(Debug More);         # 'All' plus output more details\nno re qw(Debug ALL);           # Turn on (almost) all re debugging\n# in this scope\nuse re qw(isregexp regexppattern); # import utility functions\nmy ($pat,$mods)=regexppattern(qr/foo/i);\nif (isregexp($obj)) {\nprint \"Got regexp: \",\nscalar regexppattern($obj); # just as perl would stringify\n}                                    # it but no hassle with blessed\n# re's.\n(We use $^X in these examples because it's tainted by default.)",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 49,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 1,
                "subsections": [
                    {
                        "name": "'taint' mode",
                        "lines": 5
                    },
                    {
                        "name": "'eval' mode",
                        "lines": 15
                    },
                    {
                        "name": "'strict' mode",
                        "lines": 39
                    },
                    {
                        "name": "'/flags' mode",
                        "lines": 38
                    },
                    {
                        "name": "'debug' mode",
                        "lines": 14
                    },
                    {
                        "name": "'Debug' mode",
                        "lines": 128
                    },
                    {
                        "name": "Exportable Functions",
                        "lines": 162
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "re - Perl pragma to alter regular expression behaviour\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use re 'taint';\n($x) = ($^X =~ /^(.*)$/s);     # $x is tainted here\n\n$pat = '(?{ $foo = 1 })';\nuse re 'eval';\n/foo${pat}bar/;                # won't fail (when not under -T\n# switch)\n\n{\nno re 'taint';             # the default\n($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here\n\nno re 'eval';              # the default\n/foo${pat}bar/;            # disallowed (with or without -T\n# switch)\n}\n\nuse re 'strict';               # Raise warnings for more conditions\n\nuse re '/ix';\n\"FOO\" =~ / foo /; # /ix implied\nno re '/x';\n\"FOO\" =~ /foo/; # just /i implied\n\nuse re 'debug';                # output debugging info during\n/^(.*)$/s;                     # compile and run time\n\n\nuse re 'debugcolor';           # same as 'debug', but with colored\n# output\n...\n\nuse re qw(Debug All);          # Same as \"use re 'debug'\", but you\n# can use \"Debug\" with things other\n# than 'All'\nuse re qw(Debug More);         # 'All' plus output more details\nno re qw(Debug ALL);           # Turn on (almost) all re debugging\n# in this scope\n\nuse re qw(isregexp regexppattern); # import utility functions\nmy ($pat,$mods)=regexppattern(qr/foo/i);\nif (isregexp($obj)) {\nprint \"Got regexp: \",\nscalar regexppattern($obj); # just as perl would stringify\n}                                    # it but no hassle with blessed\n# re's.\n\n(We use $^X in these examples because it's tainted by default.)\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "",
                "subsections": [
                    {
                        "name": "'taint' mode",
                        "content": "When \"use re 'taint'\" is in effect, and a tainted string is the target of a regexp, the\nregexp memories (or values returned by the m// operator in list context) are tainted.  This\nfeature is useful when regexp operations on tainted data aren't meant to extract safe\nsubstrings, but to perform other transformations.\n"
                    },
                    {
                        "name": "'eval' mode",
                        "content": "When \"use re 'eval'\" is in effect, a regexp is allowed to contain \"(?{ ... })\" zero-width\nassertions and \"(??{ ... })\" postponed subexpressions that are derived from variable\ninterpolation, rather than appearing literally within the regexp.  That is normally\ndisallowed, since it is a potential security risk.  Note that this pragma is ignored when the\nregular expression is obtained from tainted data, i.e.  evaluation is always disallowed with\ntainted regular expressions.  See \"(?{ code })\" in perlre and \"(??{ code })\" in perlre.\n\nFor the purpose of this pragma, interpolation of precompiled regular expressions (i.e., the\nresult of \"qr//\") is not considered variable interpolation.  Thus:\n\n/foo${pat}bar/\n\nis allowed if $pat is a precompiled regular expression, even if $pat contains \"(?{ ... })\"\nassertions or \"(??{ ... })\" subexpressions.\n"
                    },
                    {
                        "name": "'strict' mode",
                        "content": "Note that this is an experimental feature which may be changed or removed in a future Perl\nrelease.\n\nWhen \"use re 'strict'\" is in effect, stricter checks are applied than otherwise when\ncompiling regular expressions patterns.  These may cause more warnings to be raised than\notherwise, and more things to be fatal instead of just warnings.  The purpose of this is to\nfind and report at compile time some things, which may be legal, but have a reasonable\npossibility of not being the programmer's actual intent.  This automatically turns on the\n\"regexp\" warnings category (if not already on) within its scope.\n\nAs an example of something that is caught under \"\"strict'\", but not otherwise, is the pattern\n\nqr/\\xABC/\n\nThe \"\\x\" construct without curly braces should be followed by exactly two hex digits; this\none is followed by three.  This currently evaluates as equivalent to\n\nqr/\\x{AB}C/\n\nthat is, the character whose code point value is 0xAB, followed by the letter \"C\".  But since\n\"C\" is a hex digit, there is a reasonable chance that the intent was\n\nqr/\\x{ABC}/\n\nthat is the single character at 0xABC.  Under 'strict' it is an error to not follow \"\\x\" with\nexactly two hex digits.  When not under 'strict' a warning is generated if there is only one\nhex digit, and no warning is raised if there are more than two.\n\nIt is expected that what exactly 'strict' does will evolve over time as we gain experience\nwith it.  This means that programs that compile under it in today's Perl may not compile, or\nmay have more or fewer warnings, in future Perls.  There is no backwards compatibility\npromises with regards to it.  Also there are already proposals for an alternate syntax for\nenabling it.  For these reasons, using it will raise a \"experimental::restrict\" class\nwarning, unless that category is turned off.\n\nNote that if a pattern compiled within 'strict' is recompiled, say by interpolating into\nanother pattern, outside of 'strict', it is not checked again for strictness.  This is\nbecause if it works under strict it must work under non-strict.\n"
                    },
                    {
                        "name": "'/flags' mode",
                        "content": "When \"use re '/flags'\" is specified, the given flags are automatically added to every regular\nexpression till the end of the lexical scope.  flags can be any combination of 'a', 'aa',\n'd', 'i', 'l', 'm', 'n', 'p', 's', 'u', 'x', and/or 'xx'.\n\n\"no re '/flags'\" will turn off the effect of \"use re '/flags'\" for the given flags.\n\nFor example, if you want all your regular expressions to have /msxx on by default, simply put\n\nuse re '/msxx';\n\nat the top of your code.\n\nThe character set \"/adul\" flags cancel each other out. So, in this example,\n\nuse re \"/u\";\n\"ss\" =~ /\\xdf/;\nuse re \"/d\";\n\"ss\" =~ /\\xdf/;\n\nthe second \"use re\" does an implicit \"no re '/u'\".\n\nSimilarly,\n\nuse re \"/xx\";   # Doubled-x\n...\nuse re \"/x\";    # Single x from here on\n...\n\nTurning on one of the character set flags with \"use re\" takes precedence over the \"locale\"\npragma and the 'unicodestrings' \"feature\", for regular expressions. Turning off one of these\nflags when it is active reverts to the behaviour specified by whatever other pragmata are in\nscope. For example:\n\nuse feature \"unicodestrings\";\nno re \"/u\"; # does nothing\nuse re \"/l\";\nno re \"/l\"; # reverts to unicodestrings behaviour\n"
                    },
                    {
                        "name": "'debug' mode",
                        "content": "When \"use re 'debug'\" is in effect, perl emits debugging messages when compiling and using\nregular expressions.  The output is the same as that obtained by running a\n\"-DDEBUGGING\"-enabled perl interpreter with the -Dr switch. It may be quite voluminous\ndepending on the complexity of the match.  Using \"debugcolor\" instead of \"debug\" enables a\nform of output that can be used to get a colorful display on terminals that understand\ntermcap color sequences.  Set $ENV{PERLRETC} to a comma-separated list of \"termcap\"\nproperties to use for highlighting strings on/off, pre-point part on/off.  See \"Debugging\nRegular Expressions\" in perldebug for additional info.\n\nAs of 5.9.5 the directive \"use re 'debug'\" and its equivalents are lexically scoped, as the\nother directives are.  However they have both compile-time and run-time effects.\n\nSee \"Pragmatic Modules\" in perlmodlib.\n"
                    },
                    {
                        "name": "'Debug' mode",
                        "content": "Similarly \"use re 'Debug'\" produces debugging output, the difference being that it allows the\nfine tuning of what debugging output will be emitted. Options are divided into three groups,\nthose related to compilation, those related to execution and those related to special\npurposes. The options are as follows:\n\nCompile related options\nCOMPILE\nTurns on all non-extra compile related debug options.\n\nPARSE\nTurns on debug output related to the process of parsing the pattern.\n\nOPTIMISE\nEnables output related to the optimisation phase of compilation.\n\nTRIEC\nDetailed info about trie compilation.\n\nDUMP\nDump the final program out after it is compiled and optimised.\n\nFLAGS\nDump the flags associated with the program\n\nTEST\nPrint output intended for testing the internals of the compile process\n\nExecute related options\nEXECUTE\nTurns on all non-extra execute related debug options.\n\nMATCH\nTurns on debugging of the main matching loop.\n\nTRIEE\nExtra debugging of how tries execute.\n\nINTUIT\nEnable debugging of start-point optimisations.\n\nExtra debugging options\nEXTRA\nTurns on all \"extra\" debugging options.\n\nBUFFERS\nEnable debugging the capture group storage during match. Warning, this can\npotentially produce extremely large output.\n\nTRIEM\nEnable enhanced TRIE debugging. Enhances both TRIEE and TRIEC.\n\nSTATE\nEnable debugging of states in the engine.\n\nSTACK\nEnable debugging of the recursion stack in the engine. Enabling or disabling this\noption automatically does the same for debugging states as well. This output from\nthis can be quite large.\n\nGPOS\nEnable debugging of the \\G modifier.\n\nOPTIMISEM\nEnable enhanced optimisation debugging and start-point optimisations.  Probably not\nuseful except when debugging the regexp engine itself.\n\nOFFSETS\nDump offset information. This can be used to see how regops correlate to the pattern.\nOutput format is\n\nNODENUM:POSITION[LENGTH]\n\nWhere 1 is the position of the first char in the string. Note that position can be 0,\nor larger than the actual length of the pattern, likewise length can be zero.\n\nOFFSETSDBG\nEnable debugging of offsets information. This emits copious amounts of trace\ninformation and doesn't mesh well with other debug options.\n\nAlmost definitely only useful to people hacking on the offsets part of the debug\nengine.\n\nDUMPPREOPTIMIZE\nEnable the dumping of the compiled pattern before the optimization phase.\n\nWILDCARD\nWhen Perl encounters a wildcard subpattern, (see \"Wildcards in Property Values\" in\nperlunicode), it suspends compilation of the main pattern, compiles the subpattern,\nand then matches that against all legal possibilities to determine the actual code\npoints the subpattern matches.  After that it adds these to the main pattern, and\ncontinues its compilation.\n\nYou may very well want to see how your subpattern gets compiled, but it is likely of\nless use to you to see how Perl matches that against all the legal possibilities, as\nthat is under control of Perl, not you.   Therefore, the debugging information of the\ncompilation portion is as specified by the other options, but the debugging output of\nthe matching portion is normally suppressed.\n\nYou can use the WILDCARD option to enable the debugging output of this subpattern\nmatching.  Careful!  This can lead to voluminous outputs, and it may not make much\nsense to you what and why Perl is doing what it is.  But it may be helpful to you to\nsee why things aren't going the way you expect.\n\nNote that this option alone doesn't cause any debugging information to be output.\nWhat it does is stop the normal suppression of execution-related debugging\ninformation during the matching portion of the compilation of wildcards.  You also\nhave to specify which execution debugging information you want, such as by also\nincluding the EXECUTE option.\n\nOther useful flags\nThese are useful shortcuts to save on the typing.\n\nALL Enable all options at once except OFFSETS, OFFSETSDBG, BUFFERS, WILDCARD, and\nDUMPPREOPTIMIZE.  (To get every single option without exception, use both ALL and\nEXTRA, or starting in 5.30 on a \"-DDEBUGGING\"-enabled perl interpreter, use the -Drv\ncommand-line switches.)\n\nAll Enable DUMP and all non-extra execute options. Equivalent to:\n\nuse re 'debug';\n\nMORE\nMore\nEnable the options enabled by \"All\", plus STATE, TRIEC, and TRIEM.\n\nAs of 5.9.5 the directive \"use re 'debug'\" and its equivalents are lexically scoped, as are\nthe other directives.  However they have both compile-time and run-time effects.\n"
                    },
                    {
                        "name": "Exportable Functions",
                        "content": "As of perl 5.9.5 're' debug contains a number of utility functions that may be optionally\nexported into the caller's namespace. They are listed below.\n\nisregexp($ref)\nReturns true if the argument is a compiled regular expression as returned by \"qr//\",\nfalse if it is not.\n\nThis function will not be confused by overloading or blessing. In internals terms, this\nextracts the regexp pointer out of the PERLMAGICqr structure so it cannot be fooled.\n\nregexppattern($ref)\nIf the argument is a compiled regular expression as returned by \"qr//\", then this\nfunction returns the pattern.\n\nIn list context it returns a two element list, the first element containing the pattern\nand the second containing the modifiers used when the pattern was compiled.\n\nmy ($pat, $mods) = regexppattern($ref);\n\nIn scalar context it returns the same as perl would when stringifying a raw \"qr//\" with\nthe same pattern inside.  If the argument is not a compiled reference then this routine\nreturns false but defined in scalar context, and the empty list in list context. Thus the\nfollowing\n\nif (regexppattern($ref) eq '(?^i:foo)')\n\nwill be warning free regardless of what $ref actually is.\n\nLike \"isregexp\" this function will not be confused by overloading or blessing of the\nobject.\n\nregname($name,$all)\nReturns the contents of a named buffer of the last successful match. If $all is true,\nthen returns an array ref containing one entry per buffer, otherwise returns the first\ndefined buffer.\n\nregnames($all)\nReturns a list of all of the named buffers defined in the last successful match. If $all\nis true, then it returns all names defined, if not it returns only names which were\ninvolved in the match.\n\nregnamescount()\nReturns the number of distinct names defined in the pattern used for the last successful\nmatch.\n\nNote: this result is always the actual number of distinct named buffers defined, it may\nnot actually match that which is returned by \"regnames()\" and related routines when those\nroutines have not been called with the $all parameter set.\n\nregmust($ref)\nIf the argument is a compiled regular expression as returned by \"qr//\", then this\nfunction returns what the optimiser considers to be the longest anchored fixed string and\nlongest floating fixed string in the pattern.\n\nA fixed string is defined as being a substring that must appear for the pattern to match.\nAn anchored fixed string is a fixed string that must appear at a particular offset from\nthe beginning of the match. A floating fixed string is defined as a fixed string that can\nappear at any point in a range of positions relative to the start of the match. For\nexample,\n\nmy $qr = qr/here .* there/x;\nmy ($anchored, $floating) = regmust($qr);\nprint \"anchored:'$anchored'\\nfloating:'$floating'\\n\";\n\nresults in\n\nanchored:'here'\nfloating:'there'\n\nBecause the \"here\" is before the \".*\" in the pattern, its position can be determined\nexactly. That's not true, however, for the \"there\"; it could appear at any point after\nwhere the anchored string appeared.  Perl uses both for its optimisations, preferring the\nlonger, or, if they are equal, the floating.\n\nNOTE: This may not necessarily be the definitive longest anchored and floating string.\nThis will be what the optimiser of the Perl that you are using thinks is the longest. If\nyou believe that the result is wrong please report it via the perlbug utility.\n\noptimization($ref)\nIf the argument is a compiled regular expression as returned by \"qr//\", then this\nfunction returns a hashref of the optimization information discovered at compile time, so\nwe can write tests around it. If any other argument is given, returns \"undef\".\n\nThe hash contents are expected to change from time to time as we develop new ways to\noptimize - no assumption of stability should be made, not even between minor versions of\nperl.\n\nFor the current version, the hash will have the following contents:\n\nminlen\nAn integer, the least number of characters in any string that can match.\n\nminlenret\nAn integer, the least number of characters that can be in $& after a match. (Consider\neg \" /ns(?=\\d)/ \".)\n\ngofs\nAn integer, the number of characters before \"pos()\" to start match at.\n\nnoscan\nA boolean, \"TRUE\" to indicate that any anchored/floating substrings found should not\nbe used. (CHECKME: apparently this is set for an anchored pattern with no floating\nsubstring, but never used.)\n\nisall\nA boolean, \"TRUE\" to indicate that the optimizer information is all that the regular\nexpression contains, and thus one does not need to enter the regexp runtime engine at\nall.\n\nanchor SBOL\nA boolean, \"TRUE\" if the pattern is anchored to start of string.\n\nanchor MBOL\nA boolean, \"TRUE\" if the pattern is anchored to any start of line within the string.\n\nanchor GPOS\nA boolean, \"TRUE\" if the pattern is anchored to the end of the previous match.\n\nskip\nA boolean, \"TRUE\" if the start class can match only the first of a run.\n\nimplicit\nA boolean, \"TRUE\" if a \"/.*/\" has been turned implicitly into a \"/^.*/\".\n\nanchored/floating\nA byte string representing an anchored or floating substring respectively that any\nmatch must contain, or undef if no such substring was found, or if the substring\nwould require utf8 to represent.\n\nanchored utf8/floating utf8\nA utf8 string representing an anchored or floating substring respectively that any\nmatch must contain, or undef if no such substring was found, or if the substring\ncontains only 7-bit ASCII characters.\n\nanchored min offset/floating min offset\nAn integer, the first offset in characters from a match location at which we should\nlook for the corresponding substring.\n\nanchored max offset/floating max offset\nAn integer, the last offset in characters from a match location at which we should\nlook for the corresponding substring.\n\nIgnored for anchored, so may be 0 or same as min.\n\nanchored end shift/floating end shift\nFIXME: not sure what this is, something to do with lookbehind. regcomp.c says:\nWhen the final pattern is compiled and the data is moved from the\nscandatat structure into the regexp structure the information\nabout lookbehind is factored in, with the information that would\nhave been lost precalculated in the endshift field for the\nassociated string.\n\nchecking\nA constant string, one of \"anchored\", \"floating\" or \"none\" to indicate which\nsubstring (if any) should be checked for first.\n\nstclass\nA string representation of a character class (\"start class\") that must be the first\ncharacter of any match.\n\nTODO: explain the representations.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "\"Pragmatic Modules\" in perlmodlib.\n\n\n\nperl v5.34.0                                 2025-07-25                                    re(3perl)",
                "subsections": []
            }
        }
    }
}