in reply to Re: Why would one want in a regex a class with only a single entry?
in thread Why would one want in a regex a class with only a single entry?

Thanks, those both make sense...especially the second one. I don't use the /x modifier much (though as I'm learning, it really helps me remember why I constructed regex's a particular way after I've been away from it for a while) so that one I completely missed.

I'm curious about the first case, though. Given what I've been led to believe are the penalities of using classes, why wouldn't one check the variable to see if it has just one entry and cast it differently...i.e., in a more regex-engine-efficient form?

Just curious.

ack Albuquerque, NM
  • Comment on Re^2: Why would one want in a regex a class with only a single entry?

Replies are listed 'Best First'.
Re^3: Why would one want in a regex a class with only a single entry?
by ysth (Canon) on Mar 26, 2008 at 03:49 UTC
    Given what I've been led to believe are the penalities of using classes, why wouldn't one check the variable to see if it has just one entry and cast it differently...i.e., in a more regex-engine-efficient form?
    Because only in very unusual cases would the penalties amount to anything noticeable. And the extra code to treat one character specially means more opportunities for bugs as well as less readable/maintainable code.

    In any case, the penalty is gone in 5.10.0 and will be gone in 5.8.9.

      Good point. I suspected that was probably the case.

      Thanks, ysth.

      ack Albuquerque, NM