in reply to regular expression with @@/
According to perlretut ( here ):
And perl.com says :The escape sequence \Q ...\E quotes, or protects most non-alphabetic + characters. For instance, 1. $x = "\QThat !^*&%~& cat!"; 2. $x =~ /\Q!^*&%~&\E/; # check for rough language It does not protect $ or @ , so that variables can still be substitute +d.
You cannot include a literal $ or @ within a \Q sequence. An unescaped $ or @ interpolates the corresponding variable, while escaping will cause the literal string \$ to be matched. You'll need to write something like m/\Quser\E\@\Qhost/.So, escaping should work :
So maybe your regex isn't what you think - try a little debugging :use warnings; use strict; print "Yes!\n" if ( '$@' =~ m|\$\@| ); # prints "Yes!"
HTHuse warnings; use strict; my $string = '@@@'; if ( $string =~ m|\$\@| ){ print "Yes!\n"; } else { print "\'$string\' did not match...\n"; } # prints "'@@@' did not match..."
Update: Hmmm... damn slow typing... kennethk may have won the battle, but next time...(or not)!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regular expression with @@/
by almut (Canon) on Dec 07, 2009 at 18:32 UTC | |
by BioLion (Curate) on Dec 08, 2009 at 11:26 UTC |