{
    "mode": "perldoc",
    "parameter": "re",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/re/json",
    "generated": "2026-06-16T22:42:45Z",
    "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.)",
    "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": "'taint' mode\nWhen \"use re 'taint'\" is in effect, and a tainted string is the target of a regexp, the regexp\nmemories (or values returned by the m// operator in list context) are tainted. This feature is\nuseful when regexp operations on tainted data aren't meant to extract safe substrings, but to\nperform other transformations.\n\n'eval' mode\nWhen \"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 disallowed,\nsince it is a potential security risk. Note that this pragma is ignored when the regular\nexpression is obtained from tainted data, i.e. evaluation is always disallowed with tainted\nregular 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\n*is* allowed if $pat is a precompiled regular expression, even if $pat contains \"(?{ ... })\"\nassertions or \"(??{ ... })\" subexpressions.\n\n'strict' mode\nNote 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 compiling\nregular expressions patterns. These may cause more warnings to be raised than otherwise, and\nmore things to be fatal instead of just warnings. The purpose of this is to find and report at\ncompile time some things, which may be legal, but have a reasonable possibility of not being the\nprogrammer's actual intent. This automatically turns on the \"regexp\" warnings category (if not\nalready 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 one\nis 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 \"C\"\nis 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 hex\ndigit, 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 with\nit. This means that programs that compile under it in today's Perl may not compile, or may have\nmore or fewer warnings, in future Perls. There is no backwards compatibility promises with\nregards to it. Also there are already proposals for an alternate syntax for enabling it. For\nthese reasons, using it will raise a \"experimental::restrict\" class warning, unless that\ncategory is turned off.\n\nNote that if a pattern compiled within 'strict' is recompiled, say by interpolating into another\npattern, outside of 'strict', it is not checked again for strictness. This is because if it\nworks under strict it must work under non-strict.\n\n'/flags' mode\nWhen \"use re '/*flags*'\" is specified, the given *flags* are automatically added to every\nregular expression till the end of the lexical scope. *flags* can be any combination of 'a',\n'aa', '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\n'debug' mode\nWhen \"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 \"-DDEBUGGING\"-enabled\nperl interpreter with the -Dr switch. It may be quite voluminous depending on the complexity of\nthe match. Using \"debugcolor\" instead of \"debug\" enables a form of output that can be used to\nget a colorful display on terminals that understand termcap color sequences. Set\n$ENV{PERLRETC} to a comma-separated list of \"termcap\" properties to use for highlighting\nstrings on/off, pre-point part on/off. See \"Debugging Regular Expressions\" in perldebug for\nadditional 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\n'Debug' mode\nSimilarly \"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 purposes.\nThe options are as follows:\n\nCompile related options\n\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\n\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\n\nEXTRA\nTurns on all \"extra\" debugging options.\n\nBUFFERS\nEnable debugging the capture group storage during match. Warning, this can potentially\nproduce 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 option\nautomatically does the same for debugging states as well. This output from this can be\nquite 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, or\nlarger 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 information\nand doesn't mesh well with other debug options.\n\nAlmost definitely only useful to people hacking on the offsets part of the debug engine.\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, and\nthen matches that against all legal possibilities to determine the actual code points\nthe subpattern matches. After that it adds these to the main pattern, and continues its\ncompilation.\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 sense\nto you what and why Perl is doing what it is. But it may be helpful to you to see why\nthings aren't going the way you expect.\n\nNote that this option alone doesn't cause any debugging information to be output. What\nit does is stop the normal suppression of execution-related debugging information during\nthe matching portion of the compilation of wildcards. You also have to specify which\nexecution debugging information you want, such as by also including 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 the\nother directives. However they have both compile-time and run-time effects.\n",
            "subsections": [
                {
                    "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"
                },
                {
                    "name": "is_regexp",
                    "content": "Returns true if the argument is a compiled regular expression as returned by \"qr//\", false\nif 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"
                },
                {
                    "name": "regexp_pattern",
                    "content": "If the argument is a compiled regular expression as returned by \"qr//\", then this function\nreturns the pattern.\n\nIn list context it returns a two element list, the first element containing the pattern and\nthe 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 the\nsame pattern inside. If the argument is not a compiled reference then this routine returns\nfalse but defined in scalar context, and the empty list in list context. Thus the following\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"
                },
                {
                    "name": "regname",
                    "content": "Returns the contents of a named buffer of the last successful match. If $all is true, then\nreturns an array ref containing one entry per buffer, otherwise returns the first defined\nbuffer.\n"
                },
                {
                    "name": "regnames",
                    "content": "Returns a list of all of the named buffers defined in the last successful match. If $all is\ntrue, then it returns all names defined, if not it returns only names which were involved in\nthe match.\n"
                },
                {
                    "name": "regnames_count",
                    "content": "Returns 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 not\nactually match that which is returned by \"regnames()\" and related routines when those\nroutines have not been called with the $all parameter set.\n"
                },
                {
                    "name": "regmust",
                    "content": "If the argument is a compiled regular expression as returned by \"qr//\", then this function\nreturns what the optimiser considers to be the longest anchored fixed string and longest\nfloating 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 example,\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 where\nthe anchored string appeared. Perl uses both for its optimisations, preferring the longer,\nor, if they are equal, the floating.\n\nNOTE: This may not necessarily be the definitive longest anchored and floating string. This\nwill be what the optimiser of the Perl that you are using thinks is the longest. If you\nbelieve that the result is wrong please report it via the perlbug utility.\n"
                },
                {
                    "name": "optimization",
                    "content": "If the argument is a compiled regular expression as returned by \"qr//\", then this function\nreturns a hashref of the optimization information discovered at compile time, so we can\nwrite 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 eg\n\" /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 be\nused. (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 match\nmust contain, or undef if no such substring was found, or if the substring would require\nutf8 to represent.\n\nanchored utf8/floating utf8\nA utf8 string representing an anchored or floating substring respectively that any match\nmust contain, or undef if no such substring was found, or if the substring contains only\n7-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 look\nfor 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 look\nfor 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: When the\nfinal pattern is compiled and the data is moved from the scandatat structure into the\nregexp structure the information about lookbehind is factored in, with the information\nthat would have been lost precalculated in the endshift field for the associated\nstring.\n\nchecking\nA constant string, one of \"anchored\", \"floating\" or \"none\" to indicate which substring\n(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",
            "subsections": []
        }
    },
    "summary": "re - Perl pragma to alter regular expression behaviour",
    "flags": [],
    "examples": [],
    "see_also": []
}