Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > problem using b...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 10975 of 11531
Post > Topic >>

problem using backslash on brackets in regular expressions

by danmcclory@[EMAIL PROTECTED] (Daniel McClory) Apr 22, 2008 at 07:05 PM

Hi,

I have files which contain sentences, where some lines have extra  
information inside brackets and parentheses.  I would like to delete  
everything contained within brackets or parentheses, including the  
brackets.  I know that I am supposed to use the backslash to turn off  
the metacharacter properties of brackets and parentheses in a regular  
expression.

I am trying to use the s/// operator to remove it, by doing this:

while(<INPUT>)
   {
     $_ =~ s/\[*\]//;
     $_ =~ s/\(*\)//;
     print $_;
   }

so if the input is:
*MOT:   I'm gonna first [//] first I wanna use em all up .

then the output I'd like to get is:
*MOT:   I'm gonna first first I wanna use em all up .

but instead what I get is:
*MOT:   I'm gonna first [// first I wanna use em all up .

It only deletes the last piece, the ] bracket.  How can I erase the  
whole thing?

Thanks.
 




 5 Posts in Topic:
Joining/Merging AoA
v3gupta@[EMAIL PROTECTED]  2008-04-21 23:28:58 
problem using backslash on brackets in regular expressions
danmcclory@[EMAIL PROTECT  2008-04-22 19:05:39 
Re: problem using backslash on brackets in regular expressions
rvtol+news@[EMAIL PROTECT  2008-04-23 01:22:06 
RE: problem using backslash on brackets in regular expressions
adarsh.s85@[EMAIL PROTECT  2008-04-23 05:28:50 
RE: problem using backslash on brackets in regular expressions
"Wagner, David --- S  2008-04-22 18:17:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 1:00:58 CDT 2008.