[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] /^\Q*****\E/



On 8/16/06, Jay Hannah <jhannah@omnihotels.com> wrote:

Gotta love \Q and \E in regex's. :)

  # Set the cc_number to empty if it matches asterisks.  The Reservation
class will ignore it.
  # This is so people can change the expiration or name on card for
modifications.
  #
  $cc_number = "" if ($cc_number =~ /^\Q*****\E/);

j

>From perldoc perlre:

  \Q          quote (disable) pattern metacharacters till \E

  Today it is more common to use the quotemeta()
  function or the "\Q" metaquoting escape sequence to dis-
  able all metacharacters' special meanings like this:

    /$unquoted\Q$quoted\E$unquoted/

  Beware that if you put literal backslashes (those not
  inside interpolated variables) between "\Q" and "\E", dou-
  ble-quotish backslash interpolation may lead to confusing
  results.  If you need to use literal backslashes within
  "\Q...\E", consult "Gory details of parsing quoted con-
  structs" in perlop.

_______________________________________________
Neat stuff. I don't think I've ever used it though - although I have
used quotemeta numerous times.