> -----Original Message----- > From: Daniel McClory [mailto:[EMAIL PROTECTED] > Sent: Tuesday, April 22, 2008 16:06 > To: beginners@perl.org > Subject: problem using backslash on brackets in regular expressions > > 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/\[*\]//; What you are saying here is the first bracket can have zero or more occurances followed by a ], which is what you are seeing in your output(ie, the / before the ] is not a [ okay, then ] and replace the ] with nothing.
s/\[[^\]]+]//; > $_ =~ s/\(*\)//; s/\([^\)]+)//; No reason to do the $_ =~ as by default that is what is going to be done anyway. Wags ;) > 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. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > ********************************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ********************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/