Escaping single quote character in regular expression in mongo shell

629 views
Skip to first unread message

spen

unread,
Oct 4, 2010, 6:21:32 PM10/4/10
to mongodb-user
How do I escape the quote character in a regular expression in the
shell? For example if I want to replace it with a dash, neither of
the following work:
"Hello 'World'".replace(/\'/g, "-");
"Hello 'World'".replace(/'/g, "-");

Nosh Petigara

unread,
Oct 4, 2010, 7:50:11 PM10/4/10
to mongod...@googlegroups.com, spencer...@gmail.com
This seems to work for me

"hello 'world".replace(/\x27/g, "-")

27 is the UTF-8 character code for '

There is probably a better way to do this, though :)

--Nosh



--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Reply all
Reply to author
Forward
0 new messages