[vox-tech] Regexp question

Ken Bloom kbloom at gmail.com
Sun Jan 29 15:49:17 PST 2006


Ken Herron wrote:
> Ken Bloom wrote:
> 
>> How can I match, in one regexp strings that begin with "att_" but do not
>> begin with "att_appraisal"?
> 
> 
> In perl or something with perl's regexp capabilities, you'd use a
> negative lookahead:
> 
>     ^att_(?!appraisal)

irb(main):001:0> "att_products".match(/^att_(?!appraisal)/)
=> #<MatchData:0xb7cf80c4>
irb(main):002:0> "att_appraisal".match(/^att_(?!appraisal)/)
=> nil

Works like a charm in Ruby. Thanks!

> Without that, your best bet is to combine two regexps using boolean logic:
> 
>     if (/^att_/ && !/^att_appraisal/)

This is what I changed it to before sending the message.

> You could do this with one regexp but it's ugly:
> 
>     ^att_($|[^a]|a($|[^p]|p($|[^p]|p($[^r]|...
> 
> i.e., "att_" followed by end-of-string OR not-a OR a followed by (end of
> string OR not-p OR p followed by..

I thought of that, but I *most definitely* wasn't going to try it.

Thanks

--Ken

-- 
I usually have a GPG digital signature included as an attachment.
See http://www.gnupg.org/ for info about these digital signatures.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://ns1.livepenguin.com/pipermail/vox-tech/attachments/20060129/2ad40524/signature.pgp


More information about the vox-tech mailing list