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