Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E4BCD48EA for ; Tue, 17 May 2011 04:27:23 +0000 (UTC) Received: (qmail 29167 invoked by uid 500); 17 May 2011 04:27:22 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 28845 invoked by uid 500); 17 May 2011 04:27:19 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 28836 invoked by uid 99); 17 May 2011 04:27:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 May 2011 04:27:17 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [74.125.82.54] (HELO mail-ww0-f54.google.com) (74.125.82.54) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 May 2011 04:27:12 +0000 Received: by wwd20 with SMTP id 20so103143wwd.23 for ; Mon, 16 May 2011 21:26:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.164.199 with SMTP id f7mr148815wby.70.1305606409330; Mon, 16 May 2011 21:26:49 -0700 (PDT) Received: by 10.227.154.148 with HTTP; Mon, 16 May 2011 21:26:49 -0700 (PDT) X-Originating-IP: [156.33.195.149] Date: Mon, 16 May 2011 21:26:49 -0700 Message-ID: Subject: Case Insensitive JavaScript Regex From: Matthew Woodward To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 I'm sure I'm just messing up the syntax but I can't seem to figure out how to add the case-insensitive flag to a JavaScript regex, or at least it's not working in a temporary view. Basically I want to match a couple of individual words within a document field and this works (assuming foo is the word I want to match): function(doc) { if (doc.myfield.match(/\bfoo\b/)) { emit(null, doc); } } If I throw /i on the end of that, however, I get the "string does not eval to a function" error. I tried escaping things various ways and moving things around with no luck. This also works but I wasn't sure if this was the best way to handle it: function(doc) { if (doc.myfield.toUpperCase().match(/\bFOO\b/)) { emit(null, doc); } } Any suggestions as to why the normal /i flag doesn't do the trick, or is running toUpperCase() the way to go here? Thanks. -- Matthew Woodward matt@mattwoodward.com http://blog.mattwoodward.com identi.ca / Twitter: @mpwoodward Please do not send me proprietary file formats such as Word, PowerPoint, etc. as attachments. http://www.gnu.org/philosophy/no-word-attachments.html