develooper Front page | perl.beginners | Postings from April 2003

Re: Escaping @ symbol inside a regular expression

Thread Previous | Thread Next
From:
Sudarshan Raghavan
Date:
April 29, 2003 06:24
Subject:
Re: Escaping @ symbol inside a regular expression
Message ID:
3EAE7ECE.8010707@india.hp.com


Raja Kasinathan wrote:

>I have a pattern like s/\b\@interrupt\b//gi; This doesn't remove the
>

\b is a zero-width assertion that matches when there is \w (alphanumeric 
plus '_') on the one side and a \W (complement of \w) on the other side
perldoc perlre

In your case you have a \W on both sides and the regexp does not match. 
To explain it with an example

$_ = 'a@interrupt int func (int)'
s/\b\@interrupt\b//gi;
print;

The above code will print
a int func (inf)
The reason being you a have a \w ('a') and \W ('@') on either side and 
\b matches.

If '@interrupt' will only occur at the start of the line you can do this
s/^\@interrupt\b//i;

If you want to replace it anywhere, this is one possible way
s/(^|\s)\@interrupt\b//gi;

I must admit that I have never used or seen other's use '^'  in a '|' 
with another pattern.
It seems to work, can one of the experts second me on this one

>word @interrupt.
>from my input data
>"@interrupt void interrupt_handler(void)"
> 
>If I don't escape @, I get a warning "Possible unintended interpolation
>of @interrupt in string".
>Can anyone help me regarding this?
> 
>Cheers,
>Raja
>  
>



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About