> -----Original Message-----
> From: Daniel McClory [mailto:danmcclory@[EMAIL PROTECTED]
> Sent: Tuesday, April 22, 2008 16:06
> To: beginners@[EMAIL PROTECTED]
> Subject: problem using backslash on brackets in regular expressions
>=20
> Hi,
>=20
> I have files which contain sentences, where some lines have extra =20
> information inside brackets and parentheses. I would like to delete =20
> everything contained within brackets or parentheses, including the =20
> brackets. I know that I am supposed to use the backslash to=20
> turn off =20
> the metacharacter properties of brackets and parentheses in a=20
> regular =20
> expression.
>=20
> I am trying to use the s/// operator to remove it, by doing this:
>=20
> while(<INPUT>)
> {
> $_ =3D~ 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/\[[^\]]+]//;
> $_ =3D~ s/\(*\)//;
s/\([^\)]+)//;
No reason to do the $_ =3D~ as by default that is what is going to
be done anyway.
Wags ;)
> print $_;
> }
>=20
> so if the input is:
> *MOT: I'm gonna first [//] first I wanna use em all up .
>=20
> then the output I'd like to get is:
> *MOT: I'm gonna first first I wanna use em all up .
>=20
> but instead what I get is:
> *MOT: I'm gonna first [// first I wanna use em all up .
>=20
> It only deletes the last piece, the ] bracket. How can I erase the =20
> whole thing?
>=20
> Thanks.
>=20
> --=20
> To unsubscribe, e-mail: beginners-unsubscribe@[EMAIL PROTECTED]
> For additional commands, e-mail: beginners-help@[EMAIL PROTECTED]
> http://learn.perl.org/
>=20
>=20
>=20
**********************************************************************
This message contains information that is confidential and proprietary to
F=
edEx Freight or its affiliates. It is intended only for the recipient
name=
d and for the express purpose(s) described therein. Any other use is
proh=
ibited.
**********************************************************************


|