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 > RE: problem usi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 10975 of 11982
Post > Topic >>

RE: problem using backslash on brackets in regular expressions

by "Wagner, David --- Senior Programmer Analyst --- WGO" Apr 22, 2008 at 06:17 PM

> -----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.
**********************************************************************
 




 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 Fri Oct 10 15:06:27 CDT 2008.