{
    "mode": "perldoc",
    "parameter": "Regexp::Common::comment",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Regexp%3A%3ACommon%3A%3Acomment/json",
    "generated": "2026-06-09T12:38:46Z",
    "synopsis": "use Regexp::Common qw /comment/;\nwhile (<>) {\n/$RE{comment}{C}/       and  print \"Contains a C comment\\n\";\n/$RE{comment}{C++}/     and  print \"Contains a C++ comment\\n\";\n/$RE{comment}{PHP}/     and  print \"Contains a PHP comment\\n\";\n/$RE{comment}{Java}/    and  print \"Contains a Java comment\\n\";\n/$RE{comment}{Perl}/    and  print \"Contains a Perl comment\\n\";\n/$RE{comment}{awk}/     and  print \"Contains an awk comment\\n\";\n/$RE{comment}{HTML}/    and  print \"Contains an HTML comment\\n\";\n}\nuse Regexp::Common qw /comment REcommentHTML/;\nwhile (<>) {\n$ =~ REcommentHTML() and  print \"Contains an HTML comment\\n\";\n}",
    "sections": {
        "NAME": {
            "content": "Regexp::Common::comment -- provide regexes for comments.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Regexp::Common qw /comment/;\n\nwhile (<>) {\n/$RE{comment}{C}/       and  print \"Contains a C comment\\n\";\n/$RE{comment}{C++}/     and  print \"Contains a C++ comment\\n\";\n/$RE{comment}{PHP}/     and  print \"Contains a PHP comment\\n\";\n/$RE{comment}{Java}/    and  print \"Contains a Java comment\\n\";\n/$RE{comment}{Perl}/    and  print \"Contains a Perl comment\\n\";\n/$RE{comment}{awk}/     and  print \"Contains an awk comment\\n\";\n/$RE{comment}{HTML}/    and  print \"Contains an HTML comment\\n\";\n}\n\nuse Regexp::Common qw /comment REcommentHTML/;\n\nwhile (<>) {\n$ =~ REcommentHTML() and  print \"Contains an HTML comment\\n\";\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Please consult the manual of Regexp::Common for a general description of the works of this\ninterface.\n\nDo not use this module directly, but load it via *Regexp::Common*.\n\nThis modules gives you regular expressions for comments in various languages.\n\nTHE LANGUAGES\nBelow, the comments of each of the languages are described. The patterns are available as\n$RE{comment}{*LANG*}, foreach language *LANG*. Some languages have variants; it's described at\nthe individual languages how to get the patterns for the variants. Unless mentioned otherwise,\n\"{-keep}\" sets $1, $2, $3 and $4 to the entire comment, the opening marker, the content of the\ncomment, and the closing marker (for many languages, the latter is a newline) respectively.\n\nABC Comments in *ABC* start with a backslash (\"\\\"), and last till the end of the line. See\n<http://homepages.cwi.nl/%7Esteven/abc/>.\n\nAda Comments in *Ada* start with \"--\", and last till the end of the line.\n\nAdvisor\n*Advisor* is a language used by the HP product *glance*. Comments for this language start\nwith either \"#\" or \"//\", and last till the end of the line.\n\nAdvsys\nComments for the *Advsys* language start with \";\" and last till the end of the line. See\nalso <http://www.wurb.com/if/devsys/12>.\n\nAlan\n*Alan* comments start with \"--\", and last till the end of the line. See also\n<http://w1.132.telia.com/~u13207378/alan/manual/alanTOC.html>.\n\nAlgol 60\nComments in the *Algol 60* language start with the keyword \"comment\", and end with a \";\".\nSee <http://www.masswerk.at/algol60/report.htm>.\n\nAlgol 68\nIn *Algol 68*, comments are either delimited by \"#\", or by one of the keywords \"co\" or\n\"comment\". The keywords should not be part of another word. See\n<http://westein.arb-phys.uni-dortmund.de/~wb/a68s.txt>. With \"{-keep}\", only $1 will be set,\nreturning the entire comment.\n\nALPACA\nThe *ALPACA* language has comments starting with \"/*\" and ending with \"*/\".\n\nawk The *awk* programming language uses comments that start with \"#\" and end at the end of the\nline.\n\nB   The *B* language has comments starting with \"/*\" and ending with \"*/\".\n\nBASIC\nThere are various forms of BASIC around. Currently, we only support the variant supported by\n*mvEnterprise*, whose pattern is available as $RE{comment}{BASIC}{mvEnterprise}. Comments in\nthis language start with a \"!\", a \"*\" or the keyword \"REM\", and end till the end of the\nline. See <http://www.rainingdata.com/products/beta/docs/mve/50/ReferenceManual/Basic.pdf>.\n\nBeatnik\nThe esotoric language *Beatnik* only uses words consisting of letters. Words are scored\naccording to the rules of Scrabble. Words scoring less than 5 points, or 18 points or more\nare considered comments (although the compiler might mock at you if you score less than 5\npoints). Regardless whether \"{-keep}\", $1 will be set, and set to the entire comment. This\npattern requires *perl 5.8.0* or newer.\n\nbeta-Juliet\nThe *beta-Juliet* programming language has comments that start with \"//\" and that continue\ntill the end of the line. See also <http://www.catseye.mb.ca/esoteric/b-juliet/index.html>.\n\nBefunge-98\nThe esotoric language *Befunge-98* uses comments that start and end with a \";\". See\n<http://www.catseye.mb.ca/esoteric/befunge/98/spec98.html>.\n\nBML *BML*, or *Better Markup Language* is an HTML templating language that uses comments\nstarting with \"<?c\", and ending with \"c?>\". See\n<http://www.livejournal.com/doc/server/bml.index.html>.\n\nBrainfuck\nThe minimal language *Brainfuck* uses only eight characters, \"<\", \">\", \"[\", \"]\", \"+\", \"-\",\n\".\" and \",\". Any other characters are considered comments. With \"{-keep}\", $1 is set to the\nentire comment.\n\nC   The *C* language has comments starting with \"/*\" and ending with \"*/\".\n\nC-- The *C--* language has comments starting with \"/*\" and ending with \"*/\". See\n<http://cs.uas.arizona.edu/classes/453/programs/C--Spec.html>.\n\nC++ The *C++* language has two forms of comments. Comments that start with \"//\" and last till\nthe end of the line, and comments that start with \"/*\", and end with \"*/\". If \"{-keep}\" is\nused, only $1 will be set, and set to the entire comment.\n\nC#  The *C#* language has two forms of comments. Comments that start with \"//\" and last till the\nend of the line, and comments that start with \"/*\", and end with \"*/\". If \"{-keep}\" is used,\nonly $1 will be set, and set to the entire comment. See\n<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspe\ncC.asp>.\n\nCaml\nComments in *Caml* start with \"(*\", end with \"*)\", and can be nested. See\n<http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf> and\n<http://pauillac.inria.fr/caml/index-eng.html>.\n\nCg  The *Cg* language has two forms of comments. Comments that start with \"//\" and last till the\nend of the line, and comments that start with \"/*\", and end with \"*/\". If \"{-keep}\" is used,\nonly $1 will be set, and set to the entire comment. See\n<http://developer.nvidia.com/attach/3722>.\n\nCLU In \"CLU\", a comment starts with a procent sign (\"%\"), and ends with the next newline. See\n<ftp://ftp.lcs.mit.edu:/pub/pclu/CLU-syntax.ps> and <http://www.pmg.lcs.mit.edu/CLU.html>.\n\nCOBOL\nTraditionally, comments in *COBOL* are indicated by an asteriks in the seventh column. This\nis what the pattern matches. Modern compiler may more lenient though. See\n<http://www.csis.ul.ie/cobol/Course/COBOLIntro.htm>, and\n<http://www.csis.ul.ie/cobol/default.htm>.\n\nCQL Comments in the chess query language (*CQL*) start with a semi colon (\";\") and last till the\nend of the line. See <http://www.rbnn.com/cql/>.\n\nCrystal Report\nThe formula editor in *Crystal Reports* uses comments that start with \"//\", and end with the\nend of the line.\n\nDylan\nThere are two types of comments in *Dylan*. They either start with \"//\", or are nested\ncomments, delimited with \"/*\" and \"*/\". Under \"{-keep}\", only $1 will be set, returning the\nentire comment. This pattern requires *perl 5.6.0* or newer.\n\nECMAScript\nThe *ECMAScript* language has two forms of comments. Comments that start with \"//\" and last\ntill the end of the line, and comments that start with \"/*\", and end with \"*/\". If \"{-keep}\"\nis used, only $1 will be set, and set to the entire comment. *JavaScript* is Netscapes\nimplementation of *ECMAScript*. See\n<http://www.ecma-international.org/publications/files/ecma-st/Ecma-262.pdf>, and\n<http://www.ecma-international.org/publications/standards/Ecma-262.htm>.\n\nEiffel\n*Eiffel* comments start with \"--\", and last till the end of the line.\n\nFalse\nIn *False*, comments start with \"{\" and end with \"}\". See\n<http://wouter.fov120.com/false/false.txt>\n\nFPL The *FPL* language has two forms of comments. Comments that start with \"//\" and last till\nthe end of the line, and comments that start with \"/*\", and end with \"*/\". If \"{-keep}\" is\nused, only $1 will be set, and set to the entire comment.\n\nForth\nComments in Forth start with \"\\\", and end with the end of the line. See also\n<http://docs.sun.com/sb/doc/806-1377-10>.\n\nFortran\nThere are two forms of *Fortran*. There's free form *Fortran*, which has comments that start\nwith \"!\", and end at the end of the line. The pattern for this is given by $RE{Fortran}.\nFixed form *Fortran*, which has been obsoleted, has comments that start with \"C\", \"c\" or \"*\"\nin the first column, or with \"!\" anywhere, but the sixth column. The pattern for this are\ngiven by $RE{Fortran}{fixed}.\n\nSee also <http://www.cray.com/craydoc/manuals/007-3692-005/html-007-3692-005/>.\n\nFunge-98\nThe esotoric language *Funge-98* uses comments that start and end with a \";\".\n\nfvwm2\nConfiguration files for *fvwm2* have comments starting with a \"#\" and lasting the rest of\nthe line.\n\nHaifu\n*Haifu*, an esotoric language using haikus, has comments starting and ending with a \",\". See\n<http://www.dangermouse.net/esoteric/haifu.html>.\n\nHaskell\nThere are two types of comments in *Haskell*. They either start with at least two dashes, or\nare nested comments, delimited with \"{-\" and \"-}\". Under \"{-keep}\", only $1 will be set,\nreturning the entire comment. This pattern requires *perl 5.6.0* or newer.\n\nHTML\nIn *HTML*, comments only appear inside a *comment declaration*. A comment declaration starts\nwith a \"<!\", and ends with a \">\". Inside this declaration, we have zero or more comments.\nComments starts with \"--\" and end with \"--\", and are optionally followed by whitespace. The\npattern $RE{comment}{HTML} recognizes those comment declarations (and hence more than a\ncomment). Note that this is not the same as something that starts with \"<!--\" and ends with\n\"-->\", because the following will be matched completely:\n\n<!--  First  Comment   --\n--> Second Comment <!--\n--  Third  Comment   -->\n\nDo not be fooled by what your favourite browser thinks is an HTML comment.\n\nIf \"{-keep}\" is used, the following are returned:\n\n$1  captures the entire comment declaration.\n\n$2  captures the MDO (markup declaration open), \"<!\".\n\n$3  captures the content between the MDO and the MDC.\n\n$4  captures the (last) comment, without the surrounding dashes.\n\n$5  captures the MDC (markup declaration close), \">\".\n\nHugo\nThere are two types of comments in *Hugo*. They either start with \"!\" (which cannot be\nfollowed by a \"\\\"), or are nested comments, delimited with \"!\\\" and \"\\!\". Under \"{-keep}\",\nonly $1 will be set, returning the entire comment. This pattern requires *perl 5.6.0* or\nnewer.\n\nIcon\n*Icon* has comments that start with \"#\" and end at the next new line. See\n<http://www.toolsofcomputing.com/IconHandbook/IconHandbook.pdf>,\n<http://www.cs.arizona.edu/icon/index.htm>, and\n<http://burks.bton.ac.uk/burks/language/icon/index.htm>.\n\nILLGOL\nThe esotoric language *ILLGOL* uses comments starting with *NB* and lasting till the end of\nthe line. See <http://www.catseye.mb.ca/esoteric/illgol/index.html>.\n\nINTERCAL\nComments in INTERCAL are single line comments. They start with one of the keywords \"NOT\" or\n\"N'T\", and can optionally be preceded by the keywords \"DO\" and \"PLEASE\". If both keywords\nare used, \"PLEASE\" precedes \"DO\". Keywords are separated by whitespace.\n\nJ   The language *J* uses comments that start with \"NB.\", and that last till the end of the\nline. See <http://www.jsoftware.com/books/help/primer/contents.htm>, and\n<http://www.jsoftware.com/>.\n\nJava\nThe *Java* language has two forms of comments. Comments that start with \"//\" and last till\nthe end of the line, and comments that start with \"/*\", and end with \"*/\". If \"{-keep}\" is\nused, only $1 will be set, and set to the entire comment.\n\nJavaDoc\nThe *Javadoc* documentation syntax is demarked with a subset of ordinary Java comments to\nseparate it from code. Comments start with \"/\" end with \"*/\". If \"{-keep}\" is used, only\n$1 will be set, and set to the entire comment. See\n<http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#format>.\n\nJavaScript\nThe *JavaScript* language has two forms of comments. Comments that start with \"//\" and last\ntill the end of the line, and comments that start with \"/*\", and end with \"*/\". If \"{-keep}\"\nis used, only $1 will be set, and set to the entire comment. *JavaScript* is Netscapes\nimplementation of *ECMAScript*. See <http://www.mozilla.org/js/language/E262-3.pdf>, and\n<http://www.mozilla.org/js/language/>.\n\nLaTeX\nThe documentation language *LaTeX* uses comments starting with \"%\" and ending at the end of\nthe line.\n\nLisp\nComments in *Lisp* start with a semi-colon (\";\") and last till the end of the line.\n\nLPC The *LPC* language has comments starting with \"/*\" and ending with \"*/\".\n\nLOGO\nComments for the language *LOGO* start with \";\", and last till the end of the line.\n\nlua Comments for the *lua* language start with \"--\", and last till the end of the line. See also\n<http://www.lua.org/manual/manual.html>.\n\nM, MUMPS\nIn \"M\" (aka \"MUMPS\"), comments start with a semi-colon, and last till the end of a line. The\nlanguage specification requires the semi-colon to be preceded by one or more *linestart\ncharacter*s. Those characters default to a space, but that's configurable. This requirement,\nof preceding the comment with linestart characters is not tested for. See\n<ftp://ftp.intersys.com/pub/openm/ism/ism64docs.zip>,\n<http://mtechnology.intersys.com/mproducts/openm/index.html>, and\n<http://mcenter.com/mtrc/index.html>.\n\nm4  By default, the preprocessor language *m4* uses single line comments, that start with a \"#\"\nand continue to the end of the line, including the newline. The pattern \"$RE {comment} {m4}\"\nmatches such comments. In *m4*, it is possible to change the starting token though. See\n<http://wolfram.schneider.org/bsd/7thEdManVol2/m4/m4.pdf>,\n<http://www.cs.stir.ac.uk/~kjt/research/pdf/expl-m4.pdf>, and\n<http://www.gnu.org/software/m4/manual/>.\n\nModula-2\nIn \"Modula-2\", comments start with \"(*\", and end with \"*)\". Comments may be nested. See\n<http://www.modula2.org/>.\n\nModula-3\nIn \"Modula-3\", comments start with \"(*\", and end with \"*)\". Comments may be nested. See\n<http://www.m3.org/>.\n\nmutt\nConfiguration files for *mutt* have comments starting with a \"#\" and lasting the rest of the\nline.\n\nNickle\nThe *Nickle* language has one line comments starting with \"#\" (like Perl), or multiline\ncomments delimited by \"/*\" and \"*/\" (like C). Under \"-keep\", only $1 will be set. See also\n<http://www.nickle.org>.\n\nOberon\nComments in *Oberon* start with \"(*\" and end with \"*)\". See\n<http://www.oberon.ethz.ch/oreport.html>.\n\nPascal\nThere are many implementations of Pascal. This modules provides pattern for comments of\nseveral implementations.\n\n$RE{comment}{Pascal}\nThis is the pattern that recognizes comments according to the Pascal ISO standard. This\nstandard says that comments start with either \"{\", or \"(*\", and end with \"}\" or \"*)\".\nThis means that \"{*)\" and \"(*}\" are considered to be comments. Many Pascal applications\ndon't allow this. See <http://www.pascal-central.com/docs/iso10206.txt>\n\n$RE{comment}{Pascal}{Alice}\nThe *Alice Pascal* compiler accepts comments that start with \"{\" and end with \"}\".\nComments are not allowed to contain newlines. See\n<http://www.templetons.com/brad/alice/language/>.\n\n$RE{comment}{Pascal}{Delphi}, $RE{comment}{Pascal}{Free} and $RE{comment}{Pascal}{GPC}\nThe *Delphi Pascal*, *Free Pascal* and the *Gnu Pascal Compiler* implementations of\nPascal all have comments that either start with \"//\" and last till the end of the line,\nare delimited with \"{\" and \"}\" or are delimited with \"(*\" and \"*)\". Patterns for those\ncomments are given by $RE{comment}{Pascal}{Delphi}, $RE{comment}{Pascal}{Free} and\n$RE{comment}{Pascal}{GPC} respectively. These patterns only set $1 when \"{-keep}\" is\nused, which will then include the entire comment.\n\nSee <http://info.borland.com/techpubs/delphi5/oplg/>,\n<http://www.freepascal.org/docs-html/ref/ref.html> and <http://www.gnu-pascal.de/gpc/>.\n\n$RE{comment}{Pascal}{Workshop}\nThe *Workshop Pascal* compiler, from SUN Microsystems, allows comments that are\ndelimited with either \"{\" and \"}\", delimited with \"(*)\" and \"*\"), delimited with \"/*\",\nand \"*/\", or starting and ending with a double quote (\"\"\"). When \"{-keep}\" is used, only\n$1 is set, and returns the entire comment.\n\nSee <http://docs.sun.com/db/doc/802-5762>.\n\nPEARL\nComments in *PEARL* start with a \"!\" and last till the end of the line, or start with \"/*\"\nand end with \"*/\". With \"{-keep}\", $1 will be set to the entire comment.\n\nPHP Comments in *PHP* start with either \"#\" or \"//\" and last till the end of the line, or are\ndelimited by \"/*\" and \"*/\". With \"{-keep}\", $1 will be set to the entire comment.\n\nPL/B\nIn *PL/B*, comments start with either \".\" or \";\", and end with the next newline. See\n<http://www.mmcctech.com/pl-b/plb-0010.htm>.\n\nPL/I\nThe *PL/I* language has comments starting with \"/*\" and ending with \"*/\".\n\nPL/SQL\nIn *PL/SQL*, comments either start with \"--\" and run till the end of the line, or start with\n\"/*\" and end with \"*/\".\n\nPerl\n*Perl* uses comments that start with a \"#\", and continue till the end of the line.\n\nPortia\nThe *Portia* programming language has comments that start with \"//\", and last till the end\nof the line.\n\nPython\n*Python* uses comments that start with a \"#\", and continue till the end of the line.\n\nQ-BAL\nComments in the *Q-BAL* language start with \"`\" (a backtick), and contine till the end of\nthe line.\n\nQML In \"QML\", comments start with \"#\" and last till the end of the line. See\n<http://www.questionmark.com/uk/qml/overview.doc>.\n\nR   The statistical language *R* uses comments that start with a \"#\" and end with the following\nnew line. See <http://www.r-project.org/>.\n\nREBOL\nComments for the *REBOL* language start with \";\" and last till the end of the line.\n\nRuby\nComments in *Ruby* start with \"#\" and last till the end of the time.\n\nScheme\n*Scheme* comments start with \";\", and last till the end of the line. See\n<http://schemers.org/>.\n\nshell\nComments in various *shell*s start with a \"#\" and end at the end of the line.\n\nShelta\nThe esotoric language *Shelta* uses comments that start and end with a \";\". See\n<http://www.catseye.mb.ca/esoteric/shelta/index.html>.\n\nSLIDE\nThe *SLIDE* language has two froms of comments. First there is the line comment, which\nstarts with a \"#\" and includes the rest of the line (just like Perl). Second, there is the\nmultiline, nested comment, which are delimited by \"(*\" and \"*)\". Under C{-keep}>, only $1 is\nset, and is set to the entire comment. See\n<http://www.cs.berkeley.edu/~ug/slide/docs/slide/spec/specframeintro.shtml>.\n\nslrn\nConfiguration files for *slrn* have comments starting with a \"%\" and lasting the rest of the\nline.\n\nSmalltalk\n*Smalltalk* uses comments that start and end with a double quote, \"\"\".\n\nSMITH\nComments in the *SMITH* language start with \";\", and last till the end of the line.\n\nSqueak\nIn the Smalltalk variant *Squeak*, comments start and end with \"\"\". Double quotes can appear\ninside comments by doubling them.\n\nSQL Standard *SQL* uses comments starting with two or more dashes, and ending at the end of the\nline.\n\n*MySQL* does not follow the standard. Instead, it allows comments that start with a \"#\" or\n\"-- \" (that's two dashes and a space) ending with the following newline, and comments\nstarting with \"/*\", and ending with the next \";\" or \"*/\" that isn't inside single or double\nquotes. A pattern for this is returned by $RE{comment}{SQL}{MySQL}. With \"{-keep}\", only $1\nwill be set, and it returns the entire comment.\n\nTcl In *Tcl*, comments start with \"#\" and continue till the end of the line.\n\nTeX The documentation language *TeX* uses comments starting with \"%\" and ending at the end of\nthe line.\n\ntroff\nThe document formatting language *troff* uses comments starting with \"\\\"\", and continuing\ntill the end of the line.\n\nUbercode\nThe Windows programming language *Ubercode* uses comments that start with \"//\" and continue\nto the end of the line. See <http://www.ubercode.com>.\n\nvi  In configuration files for the editor *vi*, one can use comments starting with \"\"\", and\nending at the end of the line.\n\n*W  In the language W*, comments start with \"||\", and end with \"!!\".\n\nzonefile\nComments in DNS *zonefile*s start with \";\", and continue till the end of the line.\n\nZZT-OOP\nThe in-game language *ZZT-OOP* uses comments that start with a \"'\" character, and end at the\nfollowing newline. See <http://dave2.rocketjump.org/rad/zzthelp/lang.html>.\n",
            "subsections": []
        },
        "REFERENCES": {
            "content": "[Go 90]\nCharles F. Goldfarb: *The SGML Handbook*. Oxford: Oxford University Press. 1990. ISBN\n0-19-853737-9. Ch. 10.3, pp 390-391.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Regexp::Common for a general description of how to use this interface.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Damian Conway (damian@conway.org)\n",
            "subsections": []
        },
        "MAINTENANCE": {
            "content": "This package is maintained by Abigail (*regexp-common@abigail.be*).\n",
            "subsections": []
        },
        "BUGS AND IRRITATIONS": {
            "content": "Bound to be plenty.\n\nFor a start, there are many common regexes missing. Send them in to *regexp-common@abigail.be*.\n\nLICENSE and COPYRIGHT\nThis software is Copyright (c) 2001 - 2017, Damian Conway and Abigail.\n\nThis module is free software, and maybe used under any of the following licenses:\n\n1) The Perl Artistic License.     See the file COPYRIGHT.AL.\n2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.\n3) The BSD License.               See the file COPYRIGHT.BSD.\n4) The MIT License.               See the file COPYRIGHT.MIT.\n",
            "subsections": []
        }
    },
    "summary": "Regexp::Common::comment -- provide regexes for comments.",
    "flags": [],
    "examples": [],
    "see_also": []
}