CINXE.COM

perlfaq6 - Regular Expressions - metacpan.org

<!DOCTYPE html> <html lang="en-US"> <head> <title>perlfaq6 - Regular Expressions - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-TSLAAS2Q.css" rel="stylesheet" type="text/css"> <script src="/assets/main-PQKFM75E.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of perlfaq - MetaCPAN" href="/dist/perlfaq/releases.rss" /> <link rel="canonical" href="https://metacpan.org/dist/perlfaq/view/lib/perlfaq6.pod" /> <meta name="description" content="Regular Expressions" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/dist/perlfaq/view/lib/perlfaq6.pod" /> <meta property="og:title" content="perlfaq6" /> <meta property="og:description" content="Regular Expressions" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div class="top-notify-banner"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of perlfaq was released."> <span class="relatize">18 Feb 2024 17:37:36 UTC</span> </div> </li> <li> Distribution: <a href="/dist/perlfaq">perlfaq</a> </li> <li> <a data-keyboard-shortcut="g s" href="/dist/perlfaq/source/lib/perlfaq6.pod">Source</a> (<a href="/dist/perlfaq/source/lib/perlfaq6.pod?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/perlfaq/source/lib">Browse</a> (<a href="/dist/perlfaq/source/lib?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/perlfaq/changes">Changes</a> </li> <li> <a rel="noopener nofollow" class="nopopup" href="https://metacpan.org/release/perlfaq">Homepage</a> </li> <li> <a class="nopopup" href="/dist/perlfaq/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/perl-doc-cats/perlfaq">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://github.com/perl-doc-cats/perlfaq/issues">Issues</a> </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=perlfaq+5.20240218" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/p/perlfaq.html?oncpan=1&amp;distmat=1&amp;version=5.20240218&amp;grade=2" style="color: #090">553</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/p/perlfaq.html?oncpan=1&amp;distmat=1&amp;version=5.20240218&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/p/perlfaq.html?oncpan=1&amp;distmat=1&amp;version=5.20240218&amp;grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/ETHER/perlfaq-5.20240218">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on perlfaq who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 5 </div> </li> <li> License: perl_5 </li> <li> Perl: v5.6.0 </li> <li class="chat-banner"> <div><a rel="noopener nofollow" target="_blank" href="https://kiwiirc.com/nextclient/#irc://irc.perl.org/#perl-faq?nick=mc-guest-?">Chat with us!</a></div> </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/perlfaq/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/E/ET/ETHER/perlfaq-5.20240218.tar.gz"> Download (<span itemprop="fileSize">199.05KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FETHER%2Fperlfaq-5.20240218%2Flib%2Fperlfaq6.pod"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/perlfaq/permissions"> Permissions </a> </li> <li> <a href="/dist/perlfaq/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:perlfaq"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="perlfaq"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/ETHER/perlfaq-5.20240218/view/lib/perlfaq6.pod" >5.20240218 (ETHER on 2024-02-18)</option> <option value="/release/LLAP/perlfaq-5.021011/view/lib/perlfaq6.pod" >5.021011 (LLAP on 2016-03-04)</option> <option value="/release/FLORA/perlfaq-5.01500301/view/lib/perlfaq6.pod" >5.01500301 (FLORA on 2011-08-29)</option> <option value="/release/FLORA/perlfaq-5.015003/view/lib/perlfaq6.pod" >5.015003 (FLORA on 2011-08-26)</option> <option value="/release/FLORA/perlfaq-5.015000/view/lib/perlfaq6.pod" >5.015000 (FLORA on 2011-07-08)</option> <optgroup label="BackPAN">' <option value="/release/ETHER/perlfaq-5.20230812/view/lib/perlfaq6.pod" >5.20230812 (ETHER on 2023-08-12)</option> <option value="/release/ETHER/perlfaq-5.20230701/view/lib/perlfaq6.pod" >5.20230701 (ETHER on 2023-07-01)</option> <option value="/release/ETHER/perlfaq-5.20210520/view/lib/perlfaq6.pod" >5.20210520 (ETHER on 2021-05-20)</option> <option value="/release/ETHER/perlfaq-5.20210411/view/lib/perlfaq6.pod" >5.20210411 (ETHER on 2021-04-11)</option> <option value="/release/ETHER/perlfaq-5.20201107/view/lib/perlfaq6.pod" >5.20201107 (ETHER on 2020-11-07)</option> <option value="/release/ETHER/perlfaq-5.20200523/view/lib/perlfaq6.pod" >5.20200523 (ETHER on 2020-05-22)</option> <option value="/release/ETHER/perlfaq-5.20200522/view/lib/perlfaq6.pod" >5.20200522 (ETHER on 2020-05-22)</option> <option value="/release/ETHER/perlfaq-5.20200125/view/lib/perlfaq6.pod" >5.20200125 (ETHER on 2020-01-25)</option> <option value="/release/ETHER/perlfaq-5.20191102/view/lib/perlfaq6.pod" >5.20191102 (ETHER on 2019-11-02)</option> <option value="/release/ETHER/perlfaq-5.20190126/view/lib/perlfaq6.pod" >5.20190126 (ETHER on 2019-01-26)</option> <option value="/release/ETHER/perlfaq-5.20180915/view/lib/perlfaq6.pod" >5.20180915 (ETHER on 2018-09-15)</option> <option value="/release/ETHER/perlfaq-5.20180913/view/lib/perlfaq6.pod" >5.20180913 (ETHER on 2018-09-13)</option> <option value="/release/ETHER/perlfaq-5.20180605/view/lib/perlfaq6.pod" >5.20180605 (ETHER on 2018-06-05)</option> <option value="/release/LLAP/perlfaq-5.021010/view/lib/perlfaq6.pod" >5.021010 (LLAP on 2015-07-28)</option> <option value="/release/ETHER/perlfaq-5.021009/view/lib/perlfaq6.pod" >5.021009 (ETHER on 2015-01-25)</option> <option value="/release/ETHER/perlfaq-5.0150046/view/lib/perlfaq6.pod" >5.0150046 (ETHER on 2014-10-19)</option> <option value="/release/LLAP/perlfaq-5.0150045/view/lib/perlfaq6.pod" >5.0150045 (LLAP on 2014-08-03)</option> <option value="/release/LLAP/perlfaq-5.0150044/view/lib/perlfaq6.pod" >5.0150044 (LLAP on 2013-09-12)</option> <option value="/release/LLAP/perlfaq-5.0150043/view/lib/perlfaq6.pod" >5.0150043 (LLAP on 2013-05-12)</option> <option value="/release/LLAP/perlfaq-5.0150042/view/lib/perlfaq6.pod" >5.0150042 (LLAP on 2013-03-06)</option> <option value="/release/LLAP/perlfaq-5.0150041/view/lib/perlfaq6.pod" >5.0150041 (LLAP on 2012-08-15)</option> <option value="/release/LLAP/perlfaq-5.0150040/view/lib/perlfaq6.pod" >5.0150040 (LLAP on 2012-06-09)</option> <option value="/release/LLAP/perlfaq-5.0150039/view/lib/perlfaq6.pod" >5.0150039 (LLAP on 2012-02-18)</option> <option value="/release/LLAP/perlfaq-5.0150038/view/lib/perlfaq6.pod" >5.0150038 (LLAP on 2012-01-19)</option> <option value="/release/LLAP/perlfaq-5.0150037/view/lib/perlfaq6.pod" >5.0150037 (LLAP on 2012-01-08)</option> <option value="/release/LLAP/perlfaq-5.0150036/view/lib/perlfaq6.pod" >5.0150036 (LLAP on 2011-10-22)</option> <option value="/release/LLAP/perlfaq-5.0150035/view/lib/perlfaq6.pod" >5.0150035 (LLAP on 2011-09-26)</option> <option value="/release/LLAP/perlfaq-5.0150034/view/lib/perlfaq6.pod" >5.0150034 (LLAP on 2011-09-12)</option> <option value="/release/LLAP/perlfaq-5.0150033/view/lib/perlfaq6.pod" >5.0150033 (LLAP on 2011-08-30)</option> <option value="/release/LLAP/perlfaq-5.0150032/view/lib/perlfaq6.pod" >5.0150032 (LLAP on 2011-08-30)</option> <option value="/release/LLAP/perlfaq-5.01500302/view/lib/perlfaq6.pod" >5.01500302 (LLAP on 2011-08-29)</option> </optgroup> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20240218/lib/perlfaq6.pod" >5.20240218 (ETHER on 2024-02-18)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.021011/lib/perlfaq6.pod" >5.021011 (LLAP on 2016-03-04)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/FLORA/perlfaq-5.01500301/lib/perlfaq6.pod" >5.01500301 (FLORA on 2011-08-29)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/FLORA/perlfaq-5.015003/lib/perlfaq6.pod" >5.015003 (FLORA on 2011-08-26)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/FLORA/perlfaq-5.015000/lib/perlfaq6.pod" >5.015000 (FLORA on 2011-07-08)</option> <optgroup label="BackPAN">' <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20230812/lib/perlfaq6.pod" >5.20230812 (ETHER on 2023-08-12)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20230701/lib/perlfaq6.pod" >5.20230701 (ETHER on 2023-07-01)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20210520/lib/perlfaq6.pod" >5.20210520 (ETHER on 2021-05-20)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20210411/lib/perlfaq6.pod" >5.20210411 (ETHER on 2021-04-11)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20201107/lib/perlfaq6.pod" >5.20201107 (ETHER on 2020-11-07)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20200523/lib/perlfaq6.pod" >5.20200523 (ETHER on 2020-05-22)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20200522/lib/perlfaq6.pod" >5.20200522 (ETHER on 2020-05-22)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20200125/lib/perlfaq6.pod" >5.20200125 (ETHER on 2020-01-25)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20191102/lib/perlfaq6.pod" >5.20191102 (ETHER on 2019-11-02)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20190126/lib/perlfaq6.pod" >5.20190126 (ETHER on 2019-01-26)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20180915/lib/perlfaq6.pod" >5.20180915 (ETHER on 2018-09-15)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20180913/lib/perlfaq6.pod" >5.20180913 (ETHER on 2018-09-13)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.20180605/lib/perlfaq6.pod" >5.20180605 (ETHER on 2018-06-05)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.021010/lib/perlfaq6.pod" >5.021010 (LLAP on 2015-07-28)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.021009/lib/perlfaq6.pod" >5.021009 (ETHER on 2015-01-25)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/ETHER/perlfaq-5.0150046/lib/perlfaq6.pod" >5.0150046 (ETHER on 2014-10-19)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150045/lib/perlfaq6.pod" >5.0150045 (LLAP on 2014-08-03)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150044/lib/perlfaq6.pod" >5.0150044 (LLAP on 2013-09-12)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150043/lib/perlfaq6.pod" >5.0150043 (LLAP on 2013-05-12)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150042/lib/perlfaq6.pod" >5.0150042 (LLAP on 2013-03-06)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150041/lib/perlfaq6.pod" >5.0150041 (LLAP on 2012-08-15)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150040/lib/perlfaq6.pod" >5.0150040 (LLAP on 2012-06-09)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150039/lib/perlfaq6.pod" >5.0150039 (LLAP on 2012-02-18)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150038/lib/perlfaq6.pod" >5.0150038 (LLAP on 2012-01-19)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150037/lib/perlfaq6.pod" >5.0150037 (LLAP on 2012-01-08)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150036/lib/perlfaq6.pod" >5.0150036 (LLAP on 2011-10-22)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150035/lib/perlfaq6.pod" >5.0150035 (LLAP on 2011-09-26)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150034/lib/perlfaq6.pod" >5.0150034 (LLAP on 2011-09-12)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150033/lib/perlfaq6.pod" >5.0150033 (LLAP on 2011-08-30)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.0150032/lib/perlfaq6.pod" >5.0150032 (LLAP on 2011-08-30)</option> <option value="/release/ETHER/perlfaq-5.20240218/diff/LLAP/perlfaq-5.01500302/lib/perlfaq6.pod" >5.01500302 (LLAP on 2011-08-29)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><i>none</i></li> <li> <hr> </li> <li> <a href="/module/perlfaq6/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=perlfaq6">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=perlfaq">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/ETHER/perlfaq-5.20240218/view/lib/perlfaq6.pod">This version</a> </li> <li> <a href="/dist/perlfaq/view/lib/perlfaq6.pod">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/KBOWEN"><img src="https://www.gravatar.com/avatar/87a27cf45d31bf77e02a5b4c23d2baea?d=identicon&amp;s=20" title="KBOWEN" alt="KBOWEN"></a> <a class="display-all" href="/author/KES"><img src="https://www.gravatar.com/avatar/e8530f00b43b4f6a056f8ad4ee52ea47?d=identicon&amp;s=20" title="KES" alt="KES"></a> <a class="display-all" href="/author/DESERTFOX"><img src="https://www.gravatar.com/avatar/bedc2681974cb3fc95fcd313a66e04b4?d=identicon&amp;s=20" title="DESERTFOX" alt="DESERTFOX"></a> <a class="display-all" href="/author/RWP"><img src="https://www.gravatar.com/avatar/7110eb2389e69a066d9d7cad7a1cc2bf?d=identicon&amp;s=20" title="RWP" alt="RWP"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/perlfaq/plussers">4 PAUSE users</a> </div> <div> 8 non-PAUSE users </div> </div> </li> <li> <div> <button class="contributors-show-button btn-link">and 53 contributors</button> <div id="metacpan_contributors" class="slide-out slide-out-hidden"> <div> <ul> <li class="contributor" data-contrib-email="talexb@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Alex Beamish </li> <li class="contributor" data-cpan-author="BDFOY" data-contrib-email="bdfoy@cpan.org briandfoy@pobox.com" > <a href="/author/BDFOY" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/168427dea0a034607ee7850f3de98ea2?d=identicon&amp;s=20" /> brian d foy </a> </li> <li class="contributor" data-contrib-email="brian.fraser@booking.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Brian Fraser </li> <li class="contributor" data-contrib-email="celejar@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Celejar </li> <li class="contributor" data-cpan-author="APEIRON" data-contrib-email="apeiron@cpan.org" > <a href="/author/APEIRON" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/1a6af1c09654c59259d1ed6b08109970?d=identicon&amp;s=20" /> Chris Nehren </a> </li> <li class="contributor" data-contrib-email="walde.christian@googlemail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Christian Walde </li> <li class="contributor" data-cpan-author="CJM" data-contrib-email="perl@cjmweb.net" > <a href="/author/CJM" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/75ab2425a09e84ffc650a859523ac56a?d=identicon&amp;s=20" /> Christopher J. Madsen </a> </li> <li class="contributor" data-contrib-email="grinnz@gmail.com grinnz@grinnz.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Dan Book </li> <li class="contributor" data-contrib-email="bourbaki007@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> darfich </li> <li class="contributor" data-contrib-email="dave@dave.org.uk" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Dave Cross </li> <li class="contributor" data-cpan-author="BIGPRESH" data-contrib-email="davidp@preshweb.co.uk" > <a href="/author/BIGPRESH" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/66f9cc184db11ee7810f4bc2d029ec17?d=identicon&amp;s=20" /> David Precious </a> </li> <li class="contributor" data-contrib-email="dsteinbrunner@pobox.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> David Steinbrunner </li> <li class="contributor" data-contrib-email="dctabuyz@yandex.ru" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> dctabuyz </li> <li class="contributor" data-contrib-email="denilsonsa@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Denilson S谩 Maia </li> <li class="contributor" data-contrib-email="jenkinsd@ochin.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Douglas L. Jenkins </li> <li class="contributor" data-contrib-email="choroba@matfyz.cz" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> E. Choroba </li> <li class="contributor" data-contrib-email="eric.git@iijo.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Eric Johnson </li> <li class="contributor" data-cpan-author="SPROUT" data-contrib-email="sprout@cpan.org" > <a href="/author/SPROUT" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/30bd18493bc25ab8d09ea1050dd28f47?d=identicon&amp;s=20" /> Father Chrysostomos </a> </li> <li class="contributor" data-contrib-email="felipe@felipegasper.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Felipe Gasper </li> <li class="contributor" data-contrib-email="rafl@debian.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Florian Ragwitz </li> <li class="contributor" data-contrib-email="xaerxess@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Grzegorz Ro偶niecki </li> <li class="contributor" data-contrib-email="hemanth.hm@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> hemanth.hm </li> <li class="contributor" data-cpan-author="LICHTKIND" data-contrib-email="lichtkind@cpan.org" > <a href="/author/LICHTKIND" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/b9e7c23657e71d73dfc0f0b049a53e66?d=identicon&amp;s=20" /> Herbert Breunung </a> </li> <li class="contributor" data-cpan-author="HURRICUP" data-contrib-email="hurricup@gmail.com" > <a href="/author/HURRICUP" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/aac386b32b9399acd0ae98abadbbd608?d=identicon&amp;s=20" /> hurricup </a> </li> <li class="contributor" data-cpan-author="JKEENAN" data-contrib-email="jkeenan@cpan.org" > <a href="/author/JKEENAN" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/916bcaf0f8dbf1a198589096b293c603?d=identicon&amp;s=20" /> James E Keenan </a> </li> <li class="contributor" data-contrib-email="jeffreykegler@jeffreykegler.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Jeffrey Kegler </li> <li class="contributor" data-contrib-email="explorer@joaquinferrero.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Joaqu铆n Ferrero </li> <li class="contributor" data-cpan-author="JMASLAK" data-contrib-email="jmaslak@antelope.net" > <a href="/author/JMASLAK" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/43ad4790c6562740f661ab775418f69e?d=identicon&amp;s=20" /> Joel Maslak </a> </li> <li class="contributor" data-contrib-email="brainbuz@brainbuz.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> John Karr </li> <li class="contributor" data-contrib-email="laurent.dami@free.fr" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Laurent Dami </li> <li class="contributor" data-cpan-author="LLAP" data-contrib-email="LLAP@cpan.org leo@cuckoo.org" > <a href="/author/LLAP" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/fe83c062043dc4e41c9af07b080e306e?d=identicon&amp;s=20" /> Leo Lapworth </a> </li> <li class="contributor" data-contrib-email="l.mai@web.de" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Lukas Mai </li> <li class="contributor" data-cpan-author="MHASCH" data-contrib-email="mhasch@cpan.org" > <a href="/author/MHASCH" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/00cb277a14ecf41f329accf325a9da2d?d=identicon&amp;s=20" /> Martin Becker </a> </li> <li class="contributor" data-contrib-email="mcgrath.martin@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Martin McGrath </li> <li class="contributor" data-contrib-email="wolfsage@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Matthew Horsfall </li> <li class="contributor" data-contrib-email="schwern@pobox.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Michael G. Schwern </li> <li class="contributor" data-contrib-email="michiel.beijen@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Michiel Beijen </li> <li class="contributor" data-contrib-email="doherty@cs.dal.ca" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Mike Doherty </li> <li class="contributor" data-contrib-email="gnat@frii.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Nat Torkington </li> <li class="contributor" data-contrib-email="ntyni@debian.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Niko Tyni </li> <li class="contributor" data-contrib-email="olaf@wundersolutions.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Olaf Alders </li> <li class="contributor" data-contrib-email="perlfaq-workers@perl.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> perlfaq-workers </li> <li class="contributor" data-cpan-author="BOOK" data-contrib-email="book@cpan.org" > <a href="/author/BOOK" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/caceed5798ea9b855532b257de4686e8?d=identicon&amp;s=20" /> Philippe Bruhat (BooK) </a> </li> <li class="contributor" data-cpan-author="RJBS" data-contrib-email="rjbs@cpan.org" > <a href="/author/RJBS" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/cec6b9b88295ead26c65f8747a76561b?d=identicon&amp;s=20" /> Ricardo Signes </a> </li> <li class="contributor" data-contrib-email="ferivoz@riseup.net" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Samanta Navarro </li> <li class="contributor" data-contrib-email="kraihx@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Sebastian Riedel </li> <li class="contributor" data-contrib-email="argrath@ub32.org" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> SHIRAKATA Kentaro </li> <li class="contributor" data-contrib-email="shlomif@iglu.org.il" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Shlomi Fish </li> <li class="contributor" data-contrib-email="Smylers@stripey.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Smylers </li> <li class="contributor" data-cpan-author="P5P" data-contrib-email="perl5-porters@perl.org" > <a href="/author/P5P" class="cpan-author"> <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/3e9f73c7cca8f99ee158472e23a49eb8?d=identicon&amp;s=20" /> The Perl 5 Porters </a> </li> <li class="contributor" data-contrib-email="forum@s05.tinita.de" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> tina </li> <li class="contributor" data-contrib-email="tchrist@perl.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Tom Christiansen </li> <li class="contributor" data-contrib-email="tom@binary.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Tom Molesworth </li> </ul> </div> </div> </div> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/ETHER" class="author-name">Karen Etheridge</a> </span> <span>&nbsp;/&nbsp;</span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/ETHER/perlfaq-5.20240218/view/lib/perlfaq6.pod" >5.20240218 (ETHER on 2024-02-18)</option> <option value="/release/LLAP/perlfaq-5.021011/view/lib/perlfaq6.pod" >5.021011 (LLAP on 2016-03-04)</option> <option value="/release/FLORA/perlfaq-5.01500301/view/lib/perlfaq6.pod" >5.01500301 (FLORA on 2011-08-29)</option> <option value="/release/FLORA/perlfaq-5.015003/view/lib/perlfaq6.pod" >5.015003 (FLORA on 2011-08-26)</option> <option value="/release/FLORA/perlfaq-5.015000/view/lib/perlfaq6.pod" >5.015000 (FLORA on 2011-07-08)</option> <optgroup label="BackPAN">' <option value="/release/ETHER/perlfaq-5.20230812/view/lib/perlfaq6.pod" >5.20230812 (ETHER on 2023-08-12)</option> <option value="/release/ETHER/perlfaq-5.20230701/view/lib/perlfaq6.pod" >5.20230701 (ETHER on 2023-07-01)</option> <option value="/release/ETHER/perlfaq-5.20210520/view/lib/perlfaq6.pod" >5.20210520 (ETHER on 2021-05-20)</option> <option value="/release/ETHER/perlfaq-5.20210411/view/lib/perlfaq6.pod" >5.20210411 (ETHER on 2021-04-11)</option> <option value="/release/ETHER/perlfaq-5.20201107/view/lib/perlfaq6.pod" >5.20201107 (ETHER on 2020-11-07)</option> <option value="/release/ETHER/perlfaq-5.20200523/view/lib/perlfaq6.pod" >5.20200523 (ETHER on 2020-05-22)</option> <option value="/release/ETHER/perlfaq-5.20200522/view/lib/perlfaq6.pod" >5.20200522 (ETHER on 2020-05-22)</option> <option value="/release/ETHER/perlfaq-5.20200125/view/lib/perlfaq6.pod" >5.20200125 (ETHER on 2020-01-25)</option> <option value="/release/ETHER/perlfaq-5.20191102/view/lib/perlfaq6.pod" >5.20191102 (ETHER on 2019-11-02)</option> <option value="/release/ETHER/perlfaq-5.20190126/view/lib/perlfaq6.pod" >5.20190126 (ETHER on 2019-01-26)</option> <option value="/release/ETHER/perlfaq-5.20180915/view/lib/perlfaq6.pod" >5.20180915 (ETHER on 2018-09-15)</option> <option value="/release/ETHER/perlfaq-5.20180913/view/lib/perlfaq6.pod" >5.20180913 (ETHER on 2018-09-13)</option> <option value="/release/ETHER/perlfaq-5.20180605/view/lib/perlfaq6.pod" >5.20180605 (ETHER on 2018-06-05)</option> <option value="/release/LLAP/perlfaq-5.021010/view/lib/perlfaq6.pod" >5.021010 (LLAP on 2015-07-28)</option> <option value="/release/ETHER/perlfaq-5.021009/view/lib/perlfaq6.pod" >5.021009 (ETHER on 2015-01-25)</option> <option value="/release/ETHER/perlfaq-5.0150046/view/lib/perlfaq6.pod" >5.0150046 (ETHER on 2014-10-19)</option> <option value="/release/LLAP/perlfaq-5.0150045/view/lib/perlfaq6.pod" >5.0150045 (LLAP on 2014-08-03)</option> <option value="/release/LLAP/perlfaq-5.0150044/view/lib/perlfaq6.pod" >5.0150044 (LLAP on 2013-09-12)</option> <option value="/release/LLAP/perlfaq-5.0150043/view/lib/perlfaq6.pod" >5.0150043 (LLAP on 2013-05-12)</option> <option value="/release/LLAP/perlfaq-5.0150042/view/lib/perlfaq6.pod" >5.0150042 (LLAP on 2013-03-06)</option> <option value="/release/LLAP/perlfaq-5.0150041/view/lib/perlfaq6.pod" >5.0150041 (LLAP on 2012-08-15)</option> <option value="/release/LLAP/perlfaq-5.0150040/view/lib/perlfaq6.pod" >5.0150040 (LLAP on 2012-06-09)</option> <option value="/release/LLAP/perlfaq-5.0150039/view/lib/perlfaq6.pod" >5.0150039 (LLAP on 2012-02-18)</option> <option value="/release/LLAP/perlfaq-5.0150038/view/lib/perlfaq6.pod" >5.0150038 (LLAP on 2012-01-19)</option> <option value="/release/LLAP/perlfaq-5.0150037/view/lib/perlfaq6.pod" >5.0150037 (LLAP on 2012-01-08)</option> <option value="/release/LLAP/perlfaq-5.0150036/view/lib/perlfaq6.pod" >5.0150036 (LLAP on 2011-10-22)</option> <option value="/release/LLAP/perlfaq-5.0150035/view/lib/perlfaq6.pod" >5.0150035 (LLAP on 2011-09-26)</option> <option value="/release/LLAP/perlfaq-5.0150034/view/lib/perlfaq6.pod" >5.0150034 (LLAP on 2011-09-12)</option> <option value="/release/LLAP/perlfaq-5.0150033/view/lib/perlfaq6.pod" >5.0150033 (LLAP on 2011-08-30)</option> <option value="/release/LLAP/perlfaq-5.0150032/view/lib/perlfaq6.pod" >5.0150032 (LLAP on 2011-08-30)</option> <option value="/release/LLAP/perlfaq-5.01500302/view/lib/perlfaq6.pod" >5.01500302 (LLAP on 2011-08-29)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/perlfaq">perlfaq-5.20240218</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage zero &#10; No dependents </title> <rect x="0" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="5" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="10" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="15" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="20" y="0" width="4" height="15" fill="#e4e2e2" /> </g> </svg> </span> <div id="perlfaq-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="perlfaq-5.20240218"> <input type="hidden" name="author" value="ETHER"> <input type="hidden" name="distribution" value="perlfaq"> <button type="submit" class="favorite highlight"><span>12</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>12</span> ++</button> </div> / <span>perlfaq6</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#VERSION">VERSION</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a> <ul> <li><a href="#How-can-I-hope-to-use-regular-expressions-without-creating-illegible-and-unmaintainable-code%3F">How can I hope to use regular expressions without creating illegible and unmaintainable code? </a></li> <li><a href="#I%27m-having-trouble-matching-over-more-than-one-line.-What%27s-wrong%3F">I&#39;m having trouble matching over more than one line. What&#39;s wrong? </a></li> <li><a href="#How-can-I-pull-out-lines-between-two-patterns-that-are-themselves-on-different-lines%3F">How can I pull out lines between two patterns that are themselves on different lines? </a></li> <li><a href="#How-do-I-match-XML%2C-HTML%2C-or-other-nasty%2C-ugly-things-with-a-regex%3F">How do I match XML, HTML, or other nasty, ugly things with a regex? </a></li> <li><a href="#I-put-a-regular-expression-into-%24%2F-but-it-didn%27t-work.-What%27s-wrong%3F">I put a regular expression into $/ but it didn&#39;t work. What&#39;s wrong? </a></li> <li><a href="#How-do-I-substitute-case-insensitively-on-the-LHS-while-preserving-case-on-the-RHS%3F">How do I substitute case-insensitively on the LHS while preserving case on the RHS? </a></li> <li><a href="#How-can-I-make-%5Cw-match-national-character-sets%3F">How can I make \w match national character sets? </a></li> <li><a href="#How-can-I-match-a-locale-smart-version-of-%2F%5Ba-zA-Z%5D%2F%3F">How can I match a locale-smart version of /[a-zA-Z]/? </a></li> <li><a href="#How-can-I-quote-a-variable-to-use-in-a-regex%3F">How can I quote a variable to use in a regex? </a></li> <li><a href="#What-is-%2Fo-really-for%3F">What is /o really for? </a></li> <li><a href="#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file%3F">How do I use a regular expression to strip C-style comments from a file?</a></li> <li><a href="#Can-I-use-Perl-regular-expressions-to-match-balanced-text%3F">Can I use Perl regular expressions to match balanced text? </a></li> <li><a href="#What-does-it-mean-that-regexes-are-greedy%3F-How-can-I-get-around-it%3F">What does it mean that regexes are greedy? How can I get around it? </a></li> <li><a href="#How-do-I-process-each-word-on-each-line%3F">How do I process each word on each line? </a></li> <li><a href="#How-can-I-print-out-a-word-frequency-or-line-frequency-summary%3F">How can I print out a word-frequency or line-frequency summary?</a></li> <li><a href="#How-can-I-do-approximate-matching%3F">How can I do approximate matching? </a></li> <li><a href="#How-do-I-efficiently-match-many-regular-expressions-at-once%3F">How do I efficiently match many regular expressions at once? </a></li> <li><a href="#Why-don%27t-word-boundary-searches-with-%5Cb-work-for-me%3F">Why don&#39;t word-boundary searches with \b work for me? </a></li> <li><a href="#Why-does-using-%24%26%2C-%24%60%2C-or-%24%27-slow-my-program-down%3F">Why does using $&amp;, $`, or $&#39; slow my program down? </a></li> <li><a href="#What-good-is-%5CG-in-a-regular-expression%3F">What good is \G in a regular expression? </a></li> <li><a href="#Are-Perl-regexes-DFAs-or-NFAs%3F-Are-they-POSIX-compliant%3F">Are Perl regexes DFAs or NFAs? Are they POSIX compliant? </a></li> <li><a href="#What%27s-wrong-with-using-grep-in-a-void-context%3F">What&#39;s wrong with using grep in a void context? </a></li> <li><a href="#How-can-I-match-strings-with-multibyte-characters%3F">How can I match strings with multibyte characters? </a></li> <li><a href="#How-do-I-match-a-regular-expression-that%27s-in-a-variable%3F">How do I match a regular expression that&#39;s in a variable? </a></li> </ul> </li> <li><a href="#AUTHOR-AND-COPYRIGHT">AUTHOR AND COPYRIGHT</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>perlfaq6 - Regular Expressions</p> <h1 id="VERSION">VERSION</h1> <p>version 5.20240218</p> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>This section is surprisingly small because the rest of the FAQ is littered with answers involving regular expressions. For example, decoding a URL and checking whether something is a number can be handled with regular expressions, but those answers are found elsewhere in this document (in <a href="/pod/distribution/perlfaq/lib/perlfaq9.pod">perlfaq9</a>: &quot;How do I decode or create those %-encodings on the web&quot; and <a href="/pod/distribution/perlfaq/lib/perlfaq4.pod">perlfaq4</a>: &quot;How do I determine whether a scalar is a number/whole/integer/float&quot;, to be precise).</p> <h2 id="How-can-I-hope-to-use-regular-expressions-without-creating-illegible-and-unmaintainable-code?"><a id="How"></a><a id="How-can-I-hope-to-use-regular-expressions-without-creating-illegible-and-unmaintainable-code"></a>How can I hope to use regular expressions without creating illegible and unmaintainable code? </h2> <p>Three techniques can make regular expressions maintainable and understandable.</p> <dl> <dt id="Comments-Outside-the-Regex"><a id="Comments"></a>Comments Outside the Regex</dt> <dd> <p>Describe what you&#39;re doing and how you&#39;re doing it, using normal Perl comments.</p> <pre><code># turn the line into the first word, a colon, and the # number of characters on the rest of the line s/^(\w+)(.*)/ lc($1) . &quot;:&quot; . length($2) /meg;</code></pre> </dd> <dt id="Comments-Inside-the-Regex"><a id="Comments1"></a>Comments Inside the Regex</dt> <dd> <p>The <code>/x</code> modifier causes whitespace to be ignored in a regex pattern (except in a character class and a few other places), and also allows you to use normal comments there, too. As you can imagine, whitespace and comments help a lot.</p> <p><code>/x</code> lets you turn this:</p> <pre><code>s{&lt;(?:[^&gt;&#39;&quot;]*|&quot;.*?&quot;|&#39;.*?&#39;)+&gt;}{}gs;</code></pre> <p>into this:</p> <pre><code>s{ &lt; # opening angle bracket (?: # Non-backreffing grouping paren [^&gt;&#39;&quot;] * # 0 or more things that are neither &gt; nor &#39; nor &quot; | # or else &quot;.*?&quot; # a section between double quotes (stingy match) | # or else &#39;.*?&#39; # a section between single quotes (stingy match) ) + # all occurring one or more times &gt; # closing angle bracket }{}gsx; # replace with nothing, i.e. delete</code></pre> <p>It&#39;s still not quite so clear as prose, but it is very useful for describing the meaning of each part of the pattern.</p> </dd> <dt id="Different-Delimiters"><a id="Different"></a>Different Delimiters</dt> <dd> <p>While we normally think of patterns as being delimited with <code>/</code> characters, they can be delimited by almost any character. <a href="/pod/perlre">perlre</a> describes this. For example, the <code>s///</code> above uses braces as delimiters. Selecting another delimiter can avoid quoting the delimiter within the pattern:</p> <pre><code>s/\/usr\/local/\/usr\/share/g; # bad delimiter choice s#/usr/local#/usr/share#g; # better</code></pre> <p>Using logically paired delimiters can be even more readable:</p> <pre><code>s{/usr/local/}{/usr/share}g; # better still</code></pre> </dd> </dl> <h2 id="I&#39;m-having-trouble-matching-over-more-than-one-line.-What&#39;s-wrong?"><a id="I"></a><a id="Im-having-trouble-matching-over-more-than-one-line.-Whats-wrong"></a>I&#39;m having trouble matching over more than one line. What&#39;s wrong? </h2> <p>Either you don&#39;t have more than one line in the string you&#39;re looking at (probably), or else you aren&#39;t using the correct modifier(s) on your pattern (possibly).</p> <p>There are many ways to get multiline data into a string. If you want it to happen automatically while reading input, you&#39;ll want to set $/ (probably to &#39;&#39; for paragraphs or <code>undef</code> for the whole file) to allow you to read more than one line at a time.</p> <p>Read <a href="/pod/perlre">perlre</a> to help you decide which of <code>/s</code> and <code>/m</code> (or both) you might want to use: <code>/s</code> allows dot to include newline, and <code>/m</code> allows caret and dollar to match next to a newline, not just at the end of the string. You do need to make sure that you&#39;ve actually got a multiline string in there.</p> <p>For example, this program detects duplicate words, even when they span line breaks (but not paragraph ones). For this example, we don&#39;t need <code>/s</code> because we aren&#39;t using dot in a regular expression that we want to cross line boundaries. Neither do we need <code>/m</code> because we don&#39;t want caret or dollar to match at any point inside the record next to newlines. But it&#39;s imperative that $/ be set to something other than the default, or else we won&#39;t actually ever have a multiline record read in.</p> <pre><code>$/ = &#39;&#39;; # read in whole paragraph, not just one line while ( &lt;&gt; ) { while ( /\b([\w&#39;-]+)(\s+\g1)+\b/gi ) { # word starts alpha print &quot;Duplicate $1 at paragraph $.\n&quot;; } }</code></pre> <p>Here&#39;s some code that finds sentences that begin with &quot;From &quot; (which would be mangled by many mailers):</p> <pre><code>$/ = &#39;&#39;; # read in whole paragraph, not just one line while ( &lt;&gt; ) { while ( /^From /gm ) { # /m makes ^ match next to \n print &quot;leading From in paragraph $.\n&quot;; } }</code></pre> <p>Here&#39;s code that finds everything between START and END in a paragraph:</p> <pre><code>undef $/; # read in whole file, not just one line or paragraph while ( &lt;&gt; ) { while ( /START(.*?)END/sgm ) { # /s makes . cross line boundaries print &quot;$1\n&quot;; } }</code></pre> <h2 id="How-can-I-pull-out-lines-between-two-patterns-that-are-themselves-on-different-lines?"><a id="How1"></a><a id="How-can-I-pull-out-lines-between-two-patterns-that-are-themselves-on-different-lines"></a>How can I pull out lines between two patterns that are themselves on different lines? </h2> <p>You can use Perl&#39;s somewhat exotic <code>..</code> operator (documented in <a href="/pod/perlop">perlop</a>):</p> <pre><code>perl -ne &#39;print if /START/ .. /END/&#39; file1 file2 ...</code></pre> <p>If you wanted text and not lines, you would use</p> <pre><code>perl -0777 -ne &#39;print &quot;$1\n&quot; while /START(.*?)END/gs&#39; file1 file2 ...</code></pre> <p>But if you want nested occurrences of <code>START</code> through <code>END</code>, you&#39;ll run up against the problem described in the question in this section on matching balanced text.</p> <p>Here&#39;s another example of using <code>..</code>:</p> <pre><code>while (&lt;&gt;) { my $in_header = 1 .. /^$/; my $in_body = /^$/ .. eof; # now choose between them } continue { $. = 0 if eof; # fix $. }</code></pre> <h2 id="How-do-I-match-XML,-HTML,-or-other-nasty,-ugly-things-with-a-regex?"><a id="How2"></a><a id="How-do-I-match-XML-HTML-or-other-nasty-ugly-things-with-a-regex"></a>How do I match XML, HTML, or other nasty, ugly things with a regex? </h2> <p>Do not use regexes. Use a module and forget about the regular expressions. The <a href="/pod/XML::LibXML">XML::LibXML</a>, <a href="/pod/HTML::TokeParser">HTML::TokeParser</a> and <a href="/pod/HTML::TreeBuilder">HTML::TreeBuilder</a> modules are good starts, although each namespace has other parsing modules specialized for certain tasks and different ways of doing it. Start at CPAN Search ( <a href="http://metacpan.org/">http://metacpan.org/</a> ) and wonder at all the work people have done for you already! :)</p> <h2 id="I-put-a-regular-expression-into-$/-but-it-didn&#39;t-work.-What&#39;s-wrong?"><a id="I1"></a><a id="I-put-a-regular-expression-into-but-it-didnt-work.-Whats-wrong"></a>I put a regular expression into $/ but it didn&#39;t work. What&#39;s wrong? </h2> <p>$/ has to be a string. You can use these examples if you really need to do this.</p> <p>If you have <a href="/pod/File::Stream">File::Stream</a>, this is easy.</p> <pre><code>use File::Stream; my $stream = File::Stream-&gt;new( $filehandle, separator =&gt; qr/\s*,\s*/, ); print &quot;$_\n&quot; while &lt;$stream&gt;;</code></pre> <p>If you don&#39;t have File::Stream, you have to do a little more work.</p> <p>You can use the four-argument form of sysread to continually add to a buffer. After you add to the buffer, you check if you have a complete line (using your regular expression).</p> <pre><code>local $_ = &quot;&quot;; while( sysread FH, $_, 8192, length ) { while( s/^((?s).*?)your_pattern// ) { my $record = $1; # do stuff here. } }</code></pre> <p>You can do the same thing with foreach and a match using the c flag and the \G anchor, if you do not mind your entire file being in memory at the end.</p> <pre><code>local $_ = &quot;&quot;; while( sysread FH, $_, 8192, length ) { foreach my $record ( m/\G((?s).*?)your_pattern/gc ) { # do stuff here. } substr( $_, 0, pos ) = &quot;&quot; if pos; }</code></pre> <h2 id="How-do-I-substitute-case-insensitively-on-the-LHS-while-preserving-case-on-the-RHS?"><a id="How3"></a><a id="How-do-I-substitute-case-insensitively-on-the-LHS-while-preserving-case-on-the-RHS"></a>How do I substitute case-insensitively on the LHS while preserving case on the RHS? </h2> <p>Here&#39;s a lovely Perlish solution by Larry Rosler. It exploits properties of bitwise xor on ASCII strings.</p> <pre><code>$_= &quot;this is a TEsT case&quot;; $old = &#39;test&#39;; $new = &#39;success&#39;; s{(\Q$old\E)} { uc $new | (uc $1 ^ $1) . (uc(substr $1, -1) ^ substr $1, -1) x (length($new) - length $1) }egi; print;</code></pre> <p>And here it is as a subroutine, modeled after the above:</p> <pre><code>sub preserve_case { my ($old, $new) = @_; my $mask = uc $old ^ $old; uc $new | $mask . substr($mask, -1) x (length($new) - length($old)) } $string = &quot;this is a TEsT case&quot;; $string =~ s/(test)/preserve_case($1, &quot;success&quot;)/egi; print &quot;$string\n&quot;;</code></pre> <p>This prints:</p> <pre><code>this is a SUcCESS case</code></pre> <p>As an alternative, to keep the case of the replacement word if it is longer than the original, you can use this code, by Jeff Pinyan:</p> <pre><code>sub preserve_case { my ($from, $to) = @_; my ($lf, $lt) = map length, @_; if ($lt &lt; $lf) { $from = substr $from, 0, $lt } else { $from .= substr $to, $lf } return uc $to | ($from ^ uc $from); }</code></pre> <p>This changes the sentence to &quot;this is a SUcCess case.&quot;</p> <p>Just to show that C programmers can write C in any programming language, if you prefer a more C-like solution, the following script makes the substitution have the same case, letter by letter, as the original. (It also happens to run about 240% slower than the Perlish solution runs.) If the substitution has more characters than the string being substituted, the case of the last character is used for the rest of the substitution.</p> <pre><code># Original by Nathan Torkington, massaged by Jeffrey Friedl # sub preserve_case { my ($old, $new) = @_; my $state = 0; # 0 = no change; 1 = lc; 2 = uc my ($i, $oldlen, $newlen, $c) = (0, length($old), length($new)); my $len = $oldlen &lt; $newlen ? $oldlen : $newlen; for ($i = 0; $i &lt; $len; $i++) { if ($c = substr($old, $i, 1), $c =~ /[\W\d_]/) { $state = 0; } elsif (lc $c eq $c) { substr($new, $i, 1) = lc(substr($new, $i, 1)); $state = 1; } else { substr($new, $i, 1) = uc(substr($new, $i, 1)); $state = 2; } } # finish up with any remaining new (for when new is longer than old) if ($newlen &gt; $oldlen) { if ($state == 1) { substr($new, $oldlen) = lc(substr($new, $oldlen)); } elsif ($state == 2) { substr($new, $oldlen) = uc(substr($new, $oldlen)); } } return $new; }</code></pre> <h2 id="How-can-I-make-\w-match-national-character-sets?"><a id="How4"></a><a id="How-can-I-make-w-match-national-character-sets"></a>How can I make <code>\w</code> match national character sets? </h2> <p>Put <code>use locale;</code> in your script. The \w character class is taken from the current locale.</p> <p>See <a href="/pod/perllocale">perllocale</a> for details.</p> <h2 id="How-can-I-match-a-locale-smart-version-of-/[a-zA-Z]/?"><a id="How5"></a><a id="How-can-I-match-a-locale-smart-version-of-a-zA-Z"></a>How can I match a locale-smart version of <code>/[a-zA-Z]/</code>? </h2> <p>You can use the POSIX character class syntax <code>/[[:alpha:]]/</code> documented in <a href="/pod/perlre">perlre</a>.</p> <p>No matter which locale you are in, the alphabetic characters are the characters in \w without the digits and the underscore. As a regex, that looks like <code>/[^\W\d_]/</code>. Its complement, the non-alphabetics, is then everything in \W along with the digits and the underscore, or <code>/[\W\d_]/</code>.</p> <h2 id="How-can-I-quote-a-variable-to-use-in-a-regex?"><a id="How6"></a><a id="How-can-I-quote-a-variable-to-use-in-a-regex"></a>How can I quote a variable to use in a regex? </h2> <p>The Perl parser will expand $variable and @variable references in regular expressions unless the delimiter is a single quote. Remember, too, that the right-hand side of a <code>s///</code> substitution is considered a double-quoted string (see <a href="/pod/perlop">perlop</a> for more details). Remember also that any regex special characters will be acted on unless you precede the substitution with \Q. Here&#39;s an example:</p> <pre><code>$string = &quot;Placido P. Octopus&quot;; $regex = &quot;P.&quot;; $string =~ s/$regex/Polyp/; # $string is now &quot;Polypacido P. Octopus&quot;</code></pre> <p>Because <code>.</code> is special in regular expressions, and can match any single character, the regex <code>P.</code> here has matched the &lt;Pl&gt; in the original string.</p> <p>To escape the special meaning of <code>.</code>, we use <code>\Q</code>:</p> <pre><code>$string = &quot;Placido P. Octopus&quot;; $regex = &quot;P.&quot;; $string =~ s/\Q$regex/Polyp/; # $string is now &quot;Placido Polyp Octopus&quot;</code></pre> <p>The use of <code>\Q</code> causes the <code>.</code> in the regex to be treated as a regular character, so that <code>P.</code> matches a <code>P</code> followed by a dot.</p> <h2 id="What-is-/o-really-for?"><a id="What"></a><a id="What-is-o-really-for"></a>What is <code>/o</code> really for? </h2> <p>(contributed by brian d foy)</p> <p>The <code>/o</code> option for regular expressions (documented in <a href="/pod/perlop">perlop</a> and <a href="/pod/perlreref">perlreref</a>) tells Perl to compile the regular expression only once. This is only useful when the pattern contains a variable. Perls 5.6 and later handle this automatically if the pattern does not change.</p> <p>Since the match operator <code>m//</code>, the substitution operator <code>s///</code>, and the regular expression quoting operator <code>qr//</code> are double-quotish constructs, you can interpolate variables into the pattern. See the answer to &quot;How can I quote a variable to use in a regex?&quot; for more details.</p> <p>This example takes a regular expression from the argument list and prints the lines of input that match it:</p> <pre><code>my $pattern = shift @ARGV; while( &lt;&gt; ) { print if m/$pattern/; }</code></pre> <p>Versions of Perl prior to 5.6 would recompile the regular expression for each iteration, even if <code>$pattern</code> had not changed. The <code>/o</code> would prevent this by telling Perl to compile the pattern the first time, then reuse that for subsequent iterations:</p> <pre><code>my $pattern = shift @ARGV; while( &lt;&gt; ) { print if m/$pattern/o; # useful for Perl &lt; 5.6 }</code></pre> <p>In versions 5.6 and later, Perl won&#39;t recompile the regular expression if the variable hasn&#39;t changed, so you probably don&#39;t need the <code>/o</code> option. It doesn&#39;t hurt, but it doesn&#39;t help either. If you want any version of Perl to compile the regular expression only once even if the variable changes (thus, only using its initial value), you still need the <code>/o</code>.</p> <p>You can watch Perl&#39;s regular expression engine at work to verify for yourself if Perl is recompiling a regular expression. The <code>use re &#39;debug&#39;</code> pragma (comes with Perl 5.005 and later) shows the details. With Perls before 5.6, you should see <code>re</code> reporting that its compiling the regular expression on each iteration. With Perl 5.6 or later, you should only see <code>re</code> report that for the first iteration.</p> <pre><code>use re &#39;debug&#39;; my $regex = &#39;Perl&#39;; foreach ( qw(Perl Java Ruby Python) ) { print STDERR &quot;-&quot; x 73, &quot;\n&quot;; print STDERR &quot;Trying $_...\n&quot;; print STDERR &quot;\t$_ is good!\n&quot; if m/$regex/; }</code></pre> <h2 id="How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file?"><a id="How7"></a><a id="How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file"></a>How do I use a regular expression to strip C-style comments from a file?</h2> <p>While this actually can be done, it&#39;s much harder than you&#39;d think. For example, this one-liner</p> <pre><code>perl -0777 -pe &#39;s{/\*.*?\*/}{}gs&#39; foo.c</code></pre> <p>will work in many but not all cases. You see, it&#39;s too simple-minded for certain kinds of C programs, in particular, those with what appear to be comments in quoted strings. For that, you&#39;d need something like this, created by Jeffrey Friedl and later modified by Fred Curtis.</p> <pre><code>$/ = undef; $_ = &lt;&gt;; s#/\*[^*]*\*+([^/*][^*]*\*+)*/|(&quot;(\\.|[^&quot;\\])*&quot;|&#39;(\\.|[^&#39;\\])*&#39;|.[^/&quot;&#39;\\]*)#defined $2 ? $2 : &quot;&quot;#gse; print;</code></pre> <p>This could, of course, be more legibly written with the <code>/x</code> modifier, adding whitespace and comments. Here it is expanded, courtesy of Fred Curtis.</p> <pre><code>s{ /\* ## Start of /* ... */ comment [^*]*\*+ ## Non-* followed by 1-or-more *&#39;s ( [^/*][^*]*\*+ )* ## 0-or-more things which don&#39;t start with / ## but do end with &#39;*&#39; / ## End of /* ... */ comment | ## OR various things which aren&#39;t comments: ( &quot; ## Start of &quot; ... &quot; string ( \\. ## Escaped char | ## OR [^&quot;\\] ## Non &quot;\ )* &quot; ## End of &quot; ... &quot; string | ## OR &#39; ## Start of &#39; ... &#39; string ( \\. ## Escaped char | ## OR [^&#39;\\] ## Non &#39;\ )* &#39; ## End of &#39; ... &#39; string | ## OR . ## Anything other char [^/&quot;&#39;\\]* ## Chars which doesn&#39;t start a comment, string or escape ) }{defined $2 ? $2 : &quot;&quot;}gxse;</code></pre> <p>A slight modification also removes C++ comments, possibly spanning multiple lines using a continuation character:</p> <pre><code>s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|(&quot;(\\.|[^&quot;\\])*&quot;|&#39;(\\.|[^&#39;\\])*&#39;|.[^/&quot;&#39;\\]*)#defined $3 ? $3 : &quot;&quot;#gse;</code></pre> <h2 id="Can-I-use-Perl-regular-expressions-to-match-balanced-text?"><a id="Can"></a><a id="Can-I-use-Perl-regular-expressions-to-match-balanced-text"></a>Can I use Perl regular expressions to match balanced text? </h2> <p>(contributed by brian d foy)</p> <p>Your first try should probably be the <a href="/pod/Text::Balanced">Text::Balanced</a> module, which is in the Perl standard library since Perl 5.8. It has a variety of functions to deal with tricky text. The <a href="/pod/Regexp::Common">Regexp::Common</a> module can also help by providing canned patterns you can use.</p> <p>As of Perl 5.10, you can match balanced text with regular expressions using recursive patterns. Before Perl 5.10, you had to resort to various tricks such as using Perl code in <code>(??{})</code> sequences.</p> <p>Here&#39;s an example using a recursive regular expression. The goal is to capture all of the text within angle brackets, including the text in nested angle brackets. This sample text has two &quot;major&quot; groups: a group with one level of nesting and a group with two levels of nesting. There are five total groups in angle brackets:</p> <pre><code>I have some &lt;brackets in &lt;nested brackets&gt; &gt; and &lt;another group &lt;nested once &lt;nested twice&gt; &gt; &gt; and that&#39;s it.</code></pre> <p>The regular expression to match the balanced text uses two new (to Perl 5.10) regular expression features. These are covered in <a href="/pod/perlre">perlre</a> and this example is a modified version of one in that documentation.</p> <p>First, adding the new possessive <code>+</code> to any quantifier finds the longest match and does not backtrack. That&#39;s important since you want to handle any angle brackets through the recursion, not backtracking. The group <code>[^&lt;&gt;]++</code> finds one or more non-angle brackets without backtracking.</p> <p>Second, the new <code>(?PARNO)</code> refers to the sub-pattern in the particular capture group given by <code>PARNO</code>. In the following regex, the first capture group finds (and remembers) the balanced text, and you need that same pattern within the first buffer to get past the nested text. That&#39;s the recursive part. The <code>(?1)</code> uses the pattern in the outer capture group as an independent part of the regex.</p> <p>Putting it all together, you have:</p> <pre><code>#!/usr/local/bin/perl5.10.0 my $string =&lt;&lt;&quot;HERE&quot;; I have some &lt;brackets in &lt;nested brackets&gt; &gt; and &lt;another group &lt;nested once &lt;nested twice&gt; &gt; &gt; and that&#39;s it. HERE my @groups = $string =~ m/ ( # start of capture group 1 &lt; # match an opening angle bracket (?: [^&lt;&gt;]++ # one or more non angle brackets, non backtracking | (?1) # found &lt; or &gt;, so recurse to capture group 1 )* &gt; # match a closing angle bracket ) # end of capture group 1 /xg; $&quot; = &quot;\n\t&quot;; print &quot;Found:\n\t@groups\n&quot;;</code></pre> <p>The output shows that Perl found the two major groups:</p> <pre><code>Found: &lt;brackets in &lt;nested brackets&gt; &gt; &lt;another group &lt;nested once &lt;nested twice&gt; &gt; &gt;</code></pre> <p>With a little extra work, you can get all of the groups in angle brackets even if they are in other angle brackets too. Each time you get a balanced match, remove its outer delimiter (that&#39;s the one you just matched so don&#39;t match it again) and add it to a queue of strings to process. Keep doing that until you get no matches:</p> <pre><code>#!/usr/local/bin/perl5.10.0 my @queue =&lt;&lt;&quot;HERE&quot;; I have some &lt;brackets in &lt;nested brackets&gt; &gt; and &lt;another group &lt;nested once &lt;nested twice&gt; &gt; &gt; and that&#39;s it. HERE my $regex = qr/ ( # start of bracket 1 &lt; # match an opening angle bracket (?: [^&lt;&gt;]++ # one or more non angle brackets, non backtracking | (?1) # recurse to bracket 1 )* &gt; # match a closing angle bracket ) # end of bracket 1 /x; $&quot; = &quot;\n\t&quot;; while( @queue ) { my $string = shift @queue; my @groups = $string =~ m/$regex/g; print &quot;Found:\n\t@groups\n\n&quot; if @groups; unshift @queue, map { s/^&lt;//; s/&gt;$//; $_ } @groups; }</code></pre> <p>The output shows all of the groups. The outermost matches show up first and the nested matches show up later:</p> <pre><code>Found: &lt;brackets in &lt;nested brackets&gt; &gt; &lt;another group &lt;nested once &lt;nested twice&gt; &gt; &gt; Found: &lt;nested brackets&gt; Found: &lt;nested once &lt;nested twice&gt; &gt; Found: &lt;nested twice&gt;</code></pre> <h2 id="What-does-it-mean-that-regexes-are-greedy?-How-can-I-get-around-it?"><a id="What1"></a><a id="What-does-it-mean-that-regexes-are-greedy-How-can-I-get-around-it"></a>What does it mean that regexes are greedy? How can I get around it? </h2> <p>Most people mean that greedy regexes match as much as they can. Technically speaking, it&#39;s actually the quantifiers (<code>?</code>, <code>*</code>, <code>+</code>, <code>{}</code>) that are greedy rather than the whole pattern; Perl prefers local greed and immediate gratification to overall greed. To get non-greedy versions of the same quantifiers, use (<code>??</code>, <code>*?</code>, <code>+?</code>, <code>{}?</code>).</p> <p>An example:</p> <pre><code>my $s1 = my $s2 = &quot;I am very very cold&quot;; $s1 =~ s/ve.*y //; # I am cold $s2 =~ s/ve.*?y //; # I am very cold</code></pre> <p>Notice how the second substitution stopped matching as soon as it encountered &quot;y &quot;. The <code>*?</code> quantifier effectively tells the regular expression engine to find a match as quickly as possible and pass control on to whatever is next in line, as you would if you were playing hot potato.</p> <h2 id="How-do-I-process-each-word-on-each-line?"><a id="How8"></a><a id="How-do-I-process-each-word-on-each-line"></a>How do I process each word on each line? </h2> <p>Use the split function:</p> <pre><code>while (&lt;&gt;) { foreach my $word ( split ) { # do something with $word here } }</code></pre> <p>Note that this isn&#39;t really a word in the English sense; it&#39;s just chunks of consecutive non-whitespace characters.</p> <p>To work with only alphanumeric sequences (including underscores), you might consider</p> <pre><code>while (&lt;&gt;) { foreach $word (m/(\w+)/g) { # do something with $word here } }</code></pre> <h2 id="How-can-I-print-out-a-word-frequency-or-line-frequency-summary?"><a id="How9"></a><a id="How-can-I-print-out-a-word-frequency-or-line-frequency-summary"></a>How can I print out a word-frequency or line-frequency summary?</h2> <p>To do this, you have to parse out each word in the input stream. We&#39;ll pretend that by word you mean chunk of alphabetics, hyphens, or apostrophes, rather than the non-whitespace chunk idea of a word given in the previous question:</p> <pre><code>my (%seen); while (&lt;&gt;) { while ( /(\b[^\W_\d][\w&#39;-]+\b)/g ) { # misses &quot;`sheep&#39;&quot; $seen{$1}++; } } while ( my ($word, $count) = each %seen ) { print &quot;$count $word\n&quot;; }</code></pre> <p>If you wanted to do the same thing for lines, you wouldn&#39;t need a regular expression:</p> <pre><code>my (%seen); while (&lt;&gt;) { $seen{$_}++; } while ( my ($line, $count) = each %seen ) { print &quot;$count $line&quot;; }</code></pre> <p>If you want these output in a sorted order, see <a href="/pod/distribution/perlfaq/lib/perlfaq4.pod">perlfaq4</a>: &quot;How do I sort a hash (optionally by value instead of key)?&quot;.</p> <h2 id="How-can-I-do-approximate-matching?"><a id="How10"></a><a id="How-can-I-do-approximate-matching"></a>How can I do approximate matching? </h2> <p>See the module <a href="/pod/String::Approx">String::Approx</a> available from CPAN.</p> <h2 id="How-do-I-efficiently-match-many-regular-expressions-at-once?"><a id="How11"></a><a id="How-do-I-efficiently-match-many-regular-expressions-at-once"></a>How do I efficiently match many regular expressions at once? </h2> <p>(contributed by brian d foy)</p> <p>You want to avoid compiling a regular expression every time you want to match it. In this example, perl must recompile the regular expression for every iteration of the <code>foreach</code> loop since <code>$pattern</code> can change:</p> <pre><code>my @patterns = qw( fo+ ba[rz] ); LINE: while( my $line = &lt;&gt; ) { foreach my $pattern ( @patterns ) { if( $line =~ m/\b$pattern\b/i ) { print $line; next LINE; } } }</code></pre> <p>The <code>qr//</code> operator compiles a regular expression, but doesn&#39;t apply it. When you use the pre-compiled version of the regex, perl does less work. In this example, I inserted a <code>map</code> to turn each pattern into its pre-compiled form. The rest of the script is the same, but faster:</p> <pre><code>my @patterns = map { qr/\b$_\b/i } qw( fo+ ba[rz] ); LINE: while( my $line = &lt;&gt; ) { foreach my $pattern ( @patterns ) { if( $line =~ m/$pattern/ ) { print $line; next LINE; } } }</code></pre> <p>In some cases, you may be able to make several patterns into a single regular expression. Beware of situations that require backtracking though. In this example, the regex is only compiled once because <code>$regex</code> doesn&#39;t change between iterations:</p> <pre><code>my $regex = join &#39;|&#39;, qw( fo+ ba[rz] ); while( my $line = &lt;&gt; ) { print if $line =~ m/\b(?:$regex)\b/i; }</code></pre> <p>The function <a href="/pod/Data::Munge#list2re">&quot;list2re&quot; in Data::Munge</a> on CPAN can also be used to form a single regex that matches a list of literal strings (not regexes).</p> <p>For more details on regular expression efficiency, see <i>Mastering Regular Expressions</i> by Jeffrey Friedl. He explains how the regular expressions engine works and why some patterns are surprisingly inefficient. Once you understand how perl applies regular expressions, you can tune them for individual situations.</p> <h2 id="Why-don&#39;t-word-boundary-searches-with-\b-work-for-me?"><a id="Why"></a><a id="Why-dont-word-boundary-searches-with-b-work-for-me"></a>Why don&#39;t word-boundary searches with <code>\b</code> work for me? </h2> <p>(contributed by brian d foy)</p> <p>Ensure that you know what \b really does: it&#39;s the boundary between a word character, \w, and something that isn&#39;t a word character. That thing that isn&#39;t a word character might be \W, but it can also be the start or end of the string.</p> <p>It&#39;s not (not!) the boundary between whitespace and non-whitespace, and it&#39;s not the stuff between words we use to create sentences.</p> <p>In regex speak, a word boundary (\b) is a &quot;zero width assertion&quot;, meaning that it doesn&#39;t represent a character in the string, but a condition at a certain position.</p> <p>For the regular expression, /\bPerl\b/, there has to be a word boundary before the &quot;P&quot; and after the &quot;l&quot;. As long as something other than a word character precedes the &quot;P&quot; and succeeds the &quot;l&quot;, the pattern will match. These strings match /\bPerl\b/.</p> <pre><code>&quot;Perl&quot; # no word char before &quot;P&quot; or after &quot;l&quot; &quot;Perl &quot; # same as previous (space is not a word char) &quot;&#39;Perl&#39;&quot; # the &quot;&#39;&quot; char is not a word char &quot;Perl&#39;s&quot; # no word char before &quot;P&quot;, non-word char after &quot;l&quot;</code></pre> <p>These strings do not match /\bPerl\b/.</p> <pre><code>&quot;Perl_&quot; # &quot;_&quot; is a word char! &quot;Perler&quot; # no word char before &quot;P&quot;, but one after &quot;l&quot;</code></pre> <p>You don&#39;t have to use \b to match words though. You can look for non-word characters surrounded by word characters. These strings match the pattern /\b&#39;\b/.</p> <pre><code>&quot;don&#39;t&quot; # the &quot;&#39;&quot; char is surrounded by &quot;n&quot; and &quot;t&quot; &quot;qep&#39;a&#39;&quot; # the &quot;&#39;&quot; char is surrounded by &quot;p&quot; and &quot;a&quot;</code></pre> <p>These strings do not match /\b&#39;\b/.</p> <pre><code>&quot;foo&#39;&quot; # there is no word char after non-word &quot;&#39;&quot;</code></pre> <p>You can also use the complement of \b, \B, to specify that there should not be a word boundary.</p> <p>In the pattern /\Bam\B/, there must be a word character before the &quot;a&quot; and after the &quot;m&quot;. These patterns match /\Bam\B/:</p> <pre><code>&quot;llama&quot; # &quot;am&quot; surrounded by word chars &quot;Samuel&quot; # same</code></pre> <p>These strings do not match /\Bam\B/</p> <pre><code>&quot;Sam&quot; # no word boundary before &quot;a&quot;, but one after &quot;m&quot; &quot;I am Sam&quot; # &quot;am&quot; surrounded by non-word chars</code></pre> <h2 id="Why-does-using-$&amp;,-$`,-or-$&#39;-slow-my-program-down?"><a id="Why1"></a><a id="Why-does-using-or-slow-my-program-down"></a>Why does using $&amp;, $`, or $&#39; slow my program down? </h2> <p>(contributed by Anno Siegel)</p> <p>Once Perl sees that you need one of these variables anywhere in the program, it provides them on each and every pattern match. That means that on every pattern match the entire string will be copied, part of it to $`, part to $&amp;, and part to $&#39;. Thus the penalty is most severe with long strings and patterns that match often. Avoid $&amp;, $&#39;, and $` if you can, but if you can&#39;t, once you&#39;ve used them at all, use them at will because you&#39;ve already paid the price. Remember that some algorithms really appreciate them. As of the 5.005 release, the $&amp; variable is no longer &quot;expensive&quot; the way the other two are.</p> <p>Since Perl 5.6.1 the special variables @- and @+ can functionally replace $`, $&amp; and $&#39;. These arrays contain pointers to the beginning and end of each match (see perlvar for the full story), so they give you essentially the same information, but without the risk of excessive string copying.</p> <p>Perl 5.10 added three specials, <code>${^MATCH}</code>, <code>${^PREMATCH}</code>, and <code>${^POSTMATCH}</code> to do the same job but without the global performance penalty. Perl 5.10 only sets these variables if you compile or execute the regular expression with the <code>/p</code> modifier.</p> <h2 id="What-good-is-\G-in-a-regular-expression?"><a id="What2"></a><a id="What-good-is-G-in-a-regular-expression"></a>What good is <code>\G</code> in a regular expression? </h2> <p>You use the <code>\G</code> anchor to start the next match on the same string where the last match left off. The regular expression engine cannot skip over any characters to find the next match with this anchor, so <code>\G</code> is similar to the beginning of string anchor, <code>^</code>. The <code>\G</code> anchor is typically used with the <code>g</code> modifier. It uses the value of <code>pos()</code> as the position to start the next match. As the match operator makes successive matches, it updates <code>pos()</code> with the position of the next character past the last match (or the first character of the next match, depending on how you like to look at it). Each string has its own <code>pos()</code> value.</p> <p>Suppose you want to match all of consecutive pairs of digits in a string like &quot;1122a44&quot; and stop matching when you encounter non-digits. You want to match <code>11</code> and <code>22</code> but the letter <code>a</code> shows up between <code>22</code> and <code>44</code> and you want to stop at <code>a</code>. Simply matching pairs of digits skips over the <code>a</code> and still matches <code>44</code>.</p> <pre><code>$_ = &quot;1122a44&quot;; my @pairs = m/(\d\d)/g; # qw( 11 22 44 )</code></pre> <p>If you use the <code>\G</code> anchor, you force the match after <code>22</code> to start with the <code>a</code>. The regular expression cannot match there since it does not find a digit, so the next match fails and the match operator returns the pairs it already found.</p> <pre><code>$_ = &quot;1122a44&quot;; my @pairs = m/\G(\d\d)/g; # qw( 11 22 )</code></pre> <p>You can also use the <code>\G</code> anchor in scalar context. You still need the <code>g</code> modifier.</p> <pre><code>$_ = &quot;1122a44&quot;; while( m/\G(\d\d)/g ) { print &quot;Found $1\n&quot;; }</code></pre> <p>After the match fails at the letter <code>a</code>, perl resets <code>pos()</code> and the next match on the same string starts at the beginning.</p> <pre><code>$_ = &quot;1122a44&quot;; while( m/\G(\d\d)/g ) { print &quot;Found $1\n&quot;; } print &quot;Found $1 after while&quot; if m/(\d\d)/g; # finds &quot;11&quot;</code></pre> <p>You can disable <code>pos()</code> resets on fail with the <code>c</code> modifier, documented in <a href="/pod/perlop">perlop</a> and <a href="/pod/perlreref">perlreref</a>. Subsequent matches start where the last successful match ended (the value of <code>pos()</code>) even if a match on the same string has failed in the meantime. In this case, the match after the <code>while()</code> loop starts at the <code>a</code> (where the last match stopped), and since it does not use any anchor it can skip over the <code>a</code> to find <code>44</code>.</p> <pre><code>$_ = &quot;1122a44&quot;; while( m/\G(\d\d)/gc ) { print &quot;Found $1\n&quot;; } print &quot;Found $1 after while&quot; if m/(\d\d)/g; # finds &quot;44&quot;</code></pre> <p>Typically you use the <code>\G</code> anchor with the <code>c</code> modifier when you want to try a different match if one fails, such as in a tokenizer. Jeffrey Friedl offers this example which works in 5.004 or later.</p> <pre><code>while (&lt;&gt;) { chomp; PARSER: { m/ \G( \d+\b )/gcx &amp;&amp; do { print &quot;number: $1\n&quot;; redo; }; m/ \G( \w+ )/gcx &amp;&amp; do { print &quot;word: $1\n&quot;; redo; }; m/ \G( \s+ )/gcx &amp;&amp; do { print &quot;space: $1\n&quot;; redo; }; m/ \G( [^\w\d]+ )/gcx &amp;&amp; do { print &quot;other: $1\n&quot;; redo; }; } }</code></pre> <p>For each line, the <code>PARSER</code> loop first tries to match a series of digits followed by a word boundary. This match has to start at the place the last match left off (or the beginning of the string on the first match). Since <code>m/ \G( \d+\b )/gcx</code> uses the <code>c</code> modifier, if the string does not match that regular expression, perl does not reset pos() and the next match starts at the same position to try a different pattern.</p> <h2 id="Are-Perl-regexes-DFAs-or-NFAs?-Are-they-POSIX-compliant?"><a id="Are"></a><a id="Are-Perl-regexes-DFAs-or-NFAs-Are-they-POSIX-compliant"></a>Are Perl regexes DFAs or NFAs? Are they POSIX compliant? </h2> <p>While it&#39;s true that Perl&#39;s regular expressions resemble the DFAs (deterministic finite automata) of the egrep(1) program, they are in fact implemented as NFAs (non-deterministic finite automata) to allow backtracking and backreferencing. And they aren&#39;t POSIX-style either, because those guarantee worst-case behavior for all cases. (It seems that some people prefer guarantees of consistency, even when what&#39;s guaranteed is slowness.) See the book &quot;Mastering Regular Expressions&quot; (from O&#39;Reilly) by Jeffrey Friedl for all the details you could ever hope to know on these matters (a full citation appears in <a href="/pod/distribution/perlfaq/lib/perlfaq2.pod">perlfaq2</a>).</p> <h2 id="What&#39;s-wrong-with-using-grep-in-a-void-context?"><a id="What3"></a><a id="Whats-wrong-with-using-grep-in-a-void-context"></a>What&#39;s wrong with using grep in a void context? </h2> <p>The problem is that grep builds a return list, regardless of the context. This means you&#39;re making Perl go to the trouble of building a list that you then just throw away. If the list is large, you waste both time and space. If your intent is to iterate over the list, then use a for loop for this purpose.</p> <p>In perls older than 5.8.1, map suffers from this problem as well. But since 5.8.1, this has been fixed, and map is context aware - in void context, no lists are constructed.</p> <h2 id="How-can-I-match-strings-with-multibyte-characters?"><a id="How12"></a><a id="How-can-I-match-strings-with-multibyte-characters"></a>How can I match strings with multibyte characters? </h2> <p>Starting from Perl 5.6 Perl has had some level of multibyte character support. Perl 5.8 or later is recommended. Supported multibyte character repertoires include Unicode, and legacy encodings through the Encode module. See <a href="/pod/perluniintro">perluniintro</a>, <a href="/pod/perlunicode">perlunicode</a>, and <a href="/pod/Encode">Encode</a>.</p> <p>If you are stuck with older Perls, you can do Unicode with the <a href="/pod/Unicode::String">Unicode::String</a> module, and character conversions using the <a href="/pod/Unicode::Map8">Unicode::Map8</a> and <a href="/pod/Unicode::Map">Unicode::Map</a> modules. If you are using Japanese encodings, you might try using the jperl 5.005_03.</p> <p>Finally, the following set of approaches was offered by Jeffrey Friedl, whose article in issue #5 of The Perl Journal talks about this very matter.</p> <p>Let&#39;s suppose you have some weird Martian encoding where pairs of ASCII uppercase letters encode single Martian letters (i.e. the two bytes &quot;CV&quot; make a single Martian letter, as do the two bytes &quot;SG&quot;, &quot;VS&quot;, &quot;XX&quot;, etc.). Other bytes represent single characters, just like ASCII.</p> <p>So, the string of Martian &quot;I am CVSGXX!&quot; uses 12 bytes to encode the nine characters &#39;I&#39;, &#39; &#39;, &#39;a&#39;, &#39;m&#39;, &#39; &#39;, &#39;CV&#39;, &#39;SG&#39;, &#39;XX&#39;, &#39;!&#39;.</p> <p>Now, say you want to search for the single character <code>/GX/</code>. Perl doesn&#39;t know about Martian, so it&#39;ll find the two bytes &quot;GX&quot; in the &quot;I am CVSGXX!&quot; string, even though that character isn&#39;t there: it just looks like it is because &quot;SG&quot; is next to &quot;XX&quot;, but there&#39;s no real &quot;GX&quot;. This is a big problem.</p> <p>Here are a few ways, all painful, to deal with it:</p> <pre><code># Make sure adjacent &quot;martian&quot; bytes are no longer adjacent. $martian =~ s/([A-Z][A-Z])/ $1 /g; print &quot;found GX!\n&quot; if $martian =~ /GX/;</code></pre> <p>Or like this:</p> <pre><code>my @chars = $martian =~ m/([A-Z][A-Z]|[^A-Z])/g; # above is conceptually similar to: my @chars = $text =~ m/(.)/g; # foreach my $char (@chars) { print &quot;found GX!\n&quot;, last if $char eq &#39;GX&#39;; }</code></pre> <p>Or like this:</p> <pre><code>while ($martian =~ m/\G([A-Z][A-Z]|.)/gs) { # \G probably unneeded if ($1 eq &#39;GX&#39;) { print &quot;found GX!\n&quot;; last; } }</code></pre> <p>Here&#39;s another, slightly less painful, way to do it from Benjamin Goldberg, who uses a zero-width negative look-behind assertion.</p> <pre><code>print &quot;found GX!\n&quot; if $martian =~ m/ (?&lt;![A-Z]) (?:[A-Z][A-Z])*? GX /x;</code></pre> <p>This succeeds if the &quot;martian&quot; character GX is in the string, and fails otherwise. If you don&#39;t like using (?&lt;!), a zero-width negative look-behind assertion, you can replace (?&lt;![A-Z]) with (?:^|[^A-Z]).</p> <p>It does have the drawback of putting the wrong thing in $-[0] and $+[0], but this usually can be worked around.</p> <h2 id="How-do-I-match-a-regular-expression-that&#39;s-in-a-variable?"><a id="How13"></a><a id="How-do-I-match-a-regular-expression-thats-in-a-variable"></a>How do I match a regular expression that&#39;s in a variable? </h2> <p>(contributed by brian d foy)</p> <p>We don&#39;t have to hard-code patterns into the match operator (or anything else that works with regular expressions). We can put the pattern in a variable for later use.</p> <p>The match operator is a double quote context, so you can interpolate your variable just like a double quoted string. In this case, you read the regular expression as user input and store it in <code>$regex</code>. Once you have the pattern in <code>$regex</code>, you use that variable in the match operator.</p> <pre><code>chomp( my $regex = &lt;STDIN&gt; ); if( $string =~ m/$regex/ ) { ... }</code></pre> <p>Any regular expression special characters in <code>$regex</code> are still special, and the pattern still has to be valid or Perl will complain. For instance, in this pattern there is an unpaired parenthesis.</p> <pre><code>my $regex = &quot;Unmatched ( paren&quot;; &quot;Two parens to bind them all&quot; =~ m/$regex/;</code></pre> <p>When Perl compiles the regular expression, it treats the parenthesis as the start of a memory match. When it doesn&#39;t find the closing parenthesis, it complains:</p> <pre><code>Unmatched ( in regex; marked by &lt;-- HERE in m/Unmatched ( &lt;-- HERE paren/ at script line 3.</code></pre> <p>You can get around this in several ways depending on our situation. First, if you don&#39;t want any of the characters in the string to be special, you can escape them with <code>quotemeta</code> before you use the string.</p> <pre><code>chomp( my $regex = &lt;STDIN&gt; ); $regex = quotemeta( $regex ); if( $string =~ m/$regex/ ) { ... }</code></pre> <p>You can also do this directly in the match operator using the <code>\Q</code> and <code>\E</code> sequences. The <code>\Q</code> tells Perl where to start escaping special characters, and the <code>\E</code> tells it where to stop (see <a href="/pod/perlop">perlop</a> for more details).</p> <pre><code>chomp( my $regex = &lt;STDIN&gt; ); if( $string =~ m/\Q$regex\E/ ) { ... }</code></pre> <p>Alternately, you can use <code>qr//</code>, the regular expression quote operator (see <a href="/pod/perlop">perlop</a> for more details). It quotes and perhaps compiles the pattern, and you can apply regular expression flags to the pattern.</p> <pre><code>chomp( my $input = &lt;STDIN&gt; ); my $regex = qr/$input/is; $string =~ m/$regex/ # same as m/$input/is;</code></pre> <p>You might also want to trap any errors by wrapping an <code>eval</code> block around the whole thing.</p> <pre><code>chomp( my $input = &lt;STDIN&gt; ); eval { if( $string =~ m/\Q$input\E/ ) { ... } }; warn $@ if $@;</code></pre> <p>Or...</p> <pre><code>my $regex = eval { qr/$input/is }; if( defined $regex ) { $string =~ m/$regex/; } else { warn $@; }</code></pre> <h1 id="AUTHOR-AND-COPYRIGHT"><a id="AUTHOR"></a>AUTHOR AND COPYRIGHT</h1> <p>Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and other authors as noted. All rights reserved.</p> <p>This documentation is free; you can redistribute it and/or modify it under the same terms as Perl itself.</p> <p>Irrespective of its distribution, all code examples in this file are hereby placed into the public domain. You are permitted and encouraged to use this code in your own programs for fun or for profit as you see fit. A simple comment in the code giving credit would be courteous but is not required.</p></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install perlfaq, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm perlfaq</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install perlfaq</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10