I was reading a Meditations node, by moritz. The subject was The cost of unchecked best practices.

His discussion was related to some issues with respect to best practices and some code strategies of another monk in another posting.

But, as a part of his discussion he noted:

This optimization is not performed for char classes with single entries.

I understand completely what moritz was talking about; but his comment got me to thinking and peaked my curiosity.

Classes in regexes, I am told, are somewhat slow (I believe the tend to cause a lot of backtracking as it tests the various alternatives in the class until it finds one that matches...or until none are found to match). The moritz comment leads me to believe that there are, for some programmers, a value to having a regex class with only a single entry; but I don't see the value.

My question is: Why would one want a class with a single entry in a regex?

ack Albuquerque, NM

In reply to Why would one want in a regex a class with only a single entry? by ack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.