From: dblack@... Date: 2002-09-08T06:23:30+09:00 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