> -----Original Message----- > From: Booher Timothy B 1stLt AFRL/MNAC > [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, December 12, 2001 2:57 PM > To: [EMAIL PROTECTED] > Subject: quick regex question > > > o.k. another regex issue . . . I want a one-liner that can > remove everything > after a given character: i.e. > > in this case everything after ! (fortran comment): > > would this work: > > perl -npe 's/\!.+$//' > > my thinking is that \! Is the literal character and . would count for > anything + would represent any number of anything and $ would > symbolize the > end of the line. Am I close, if so how close?
You are pretty close. Note that: 1) You wouldn't use both -n and -p switches. Just use -p in this case. 2) . doesn't match "anything". By default, it doesn't match a newline (in this case, that's probably what you want). 3) The + means "one or more", so you won't match if the bang is at the end of the line. May want to change to .* (* = match 0 or more). 4) Your regex removes the bang as well as what follows. 5) You need to watch out for a bang that is not a comment marker (perhaps in a quoted literal). The solution to this is non-trivial. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]