Path: utzoo!attcan!uunet!bfmny0!tneff From: tneff@bfmny0.BFM.COM (Tom Neff) Newsgroups: comp.lang.perl Subject: Re: Regexps (was Re: Changing the first character of a string.) Message-ID: <15634@bfmny0.BFM.COM> Date: 3 Jul 90 20:03:50 GMT References: <1990Jul3.144552.5407@uvaarpa.Virginia.EDU> <1990Jul3.184351.3820@iwarp.intel.com> Reply-To: tneff@bfmny0.BFM.COM (Tom Neff) Lines: 30 In article <1990Jul3.184351.3820@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >I frequently run up against * and + matching a bit too much, and want >to "back it off" a bit, but have found the problem without general >solution. > >For example, matching the first two-digit number in a line, discarding >all text before it. I want to write: > > s/.*(\d\d)/\1/; > >but instead am forced to do something like: > > /\d\d.*/; $_ = $&; Try /\d\d.*\n?$/ && $_ = $&; or my fave /\d{2}/ && substr($_,0,length($`)) = ''; This doesn't lose the newline and you don't care what comes after. (I wish Larry'd make $` and $' lvalues, hehe.) -- "My God, Thiokol, when do you \\ Tom Neff want me to launch? Next April?" \\ tneff@bfmny0.BFM.COM