If you intended to refer to the first captured group you probably want $1 instead of $0*, but before that you would need to create a capture group with round brackets "()", like:
doc.EntityType.replace(/([A-Z])/g, ' [$0]'); which would replace each capital letter with itself in square brackets. Good luck! * https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/String/Replace On Fri, Nov 20, 2009 at 8:37 AM, Eric Desgranges (JIRA) <[email protected]> wrote: > Regex capture problem in emit functions > --------------------------------------- > > Key: COUCHDB-573 > URL: https://issues.apache.org/jira/browse/COUCHDB-573 > Project: CouchDB > Issue Type: Bug > Affects Versions: 0.11 > Environment: Linux > Reporter: Eric Desgranges > Priority: Trivial > Fix For: 0.11 > > > The capture variables $0, $1, $2... don't get instantiated in regex > expressions placed in emit functions. > > Example: > function(doc) { if (doc.EntityType != null) { emit(doc.ID.Value + '.' + > doc.EntityType, { Type: doc.EntityType.replace(/[A-Z]/g, ' $0'), .... > > EntityType: TestTwo > Returns: > Type: " $0est $0wo" > > Instead of: > Type: " Test Two" > > > > > > > -- > This message is automatically generated by JIRA. > - > You can reply to this email to add a comment to the issue online. > >
