You should be able to use xregexp library for that. I think it supports
this case exactly. I'll have to look at the documentation.
On Mar 2, 2013 12:40 PM, "Simon Kornblith" <notifications@github.com> wrote:

> In chrome/content/zotero/rtfScan.js:
>
> > @@ -167,7 +167,10 @@ var Zotero_RTFScan = new function() {
> >  		// read through RTF file and display items as they're found
> >  		// we could read the file in chunks, but unless people start having memory issues, it's
> >  		// probably faster and definitely simpler if we don't
> > -		contents = Zotero.File.getContents(inputFile).replace(/([^\\\r])\r?\n/, "$1 ").replace("\\'92", "'", "g").replace("\\rquote ", "’");
> > +		// unescape first utf then hexdec characters. E.g. LibreOffice prints both, so we want to get rid of immediately
> > +		// following hexdec when unescaping utf
> > +		contents = Zotero.File.getContents(inputFile).replace(/([^\\\r])\r?\n/, "$1 ").replace("\\'92", "'", "g").replace("\\rquote ", "’").replace(/(\uc\d+)?\\u(\d+)(\\\'..)?(\{.*\})?/g, function(){ return String.fromCharCode(arguments[2])}).replace(/(\uc\d+)?\\\'(..)(\{.*\})?/g, function(){return String.fromCharCode(parseInt(arguments[2], 16))});
>
>
>    - This is a really long line, and should be broken into several that
>    aren'tquite so long (probably at the .s after replace)
>    - What does \\\'.. match? Is there a way the .s can be more specific?
>    - (\{.*\})? probably doesn't do what you want. What case are you
>    trying to handle here? I think \{.*\} will match from the next open
>    bracket to the last close bracket in the document because * is greedy,
>    which could be bad. It's impossible to match what's inside the brackets
>    properly, since JavaScript doesn't support recursive regexps. \{[^}]*\}will match from the next open bracket to the next close bracket, but this
>    might actually end up generating an invalid RTF document if there's another
>    open bracket before the next close bracket, which would also be bad.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/zotero/zotero/pull/255/files#r3215652>
> .
>