From: Rich Kilmer Date: 2002-09-08T06:32:17+09:00 Subject: RE: Regular expression question Actually I did not need the - so the /\Adec(?[\w])/ worked great. Thank you my RegEx guru ;-) -rich > -----Original Message----- > From: dblack@candle.superlink.net > [mailto:dblack@candle.superlink.net] > Sent: Saturday, September 07, 2002 5:24 PM > To: ruby-talk ML > Subject: Re: Regular expression question > > > Hi -- > > On Sun, 8 Sep 2002, Rich Kilmer wrote: > > > As I don't have my copy of Mastering Regular Expressions at > home, and > > I'm not that good with them (yet :-) I question for the RegEx gurus: > > Answering questions addressed to gurus is usually a guarantee > that I'll get it wrong, but I'll try anyway :-) > > > if I want to match "dec" at the beginning of a string how would I do > > that: > > > > /\Adec/ > > > > matches on string "decimal" and "dec" basically I want 'dec' not > > followed by [A-Za-z0-9_-] but anything else is ok (including 'dec' > > being the entire string) > > You want a negative lookahead: > > /\Adec(?![A-Za-z0-9_-])/ > > You can shorten it to: > > /\Adec(?![\w-])/ > > the difference being that \w is locale-dependent (which is > quite likely good, if you want to avoid all alphanumeric characters). > > > David > > -- > David Alan Black | Register for RubyConf 2002! > home: dblack@candle.superlink.net | November 1-3 > work: blackdav@shu.edu | Seattle, WA, USA > Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com > >