incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Woodward <>
Subject Case Insensitive JavaScript Regex
Date Tue, 17 May 2011 04:26:49 GMT
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

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?


Matthew Woodward / Twitter: @mpwoodward

Please do not send me proprietary file formats such as Word,
PowerPoint, etc. as attachments.

View raw message