tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: Much obliged, monks. Cutting to the good part, it seems my question can best be answered with: use quotemeta, and compile the result with qr.use strict; use warnings; use Test::More qw(no_plan); like('a',qr/a/); #passes like('(',qr/\Q(\E/); #passes -- \Q\E works for parenthesis and most sp +ecial characters like('asdf$',qr/\Qasdf$\E/); #no -- but not for the dollar sign like('asdf$',qr/\Qasdf\$\E/); #no like('asdf$',qr/asdf$/); #no like('asdf$',qr/\$/); #passes -- you have to backslash the dollar
use strict; use warnings; use Test::More qw(no_plan); like('asdf$', quotemeta('asdf$')); #fails my $re = quotemeta('asdf$'); like('asdf$', qr/$re/); #passes like('asdf$', qr/@{[ quotemeta('asdf$') ]}/); #passes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can I use Q and E to regex match the dollar sign?
by borisz (Canon) on Aug 30, 2005 at 18:21 UTC | |
by radiantmatrix (Parson) on Aug 30, 2005 at 19:36 UTC | |
|
Re: Can I use Q and E to regex match the dollar sign?
by ikegami (Patriarch) on Aug 30, 2005 at 18:37 UTC |