Groups in Regular Expressions in Zotero

Hi,

I'm having a recurrent issue when dealing with Regular Expressions in Zotero where I need to work with groups. It's probably a misunderstanding on my side so probably you'll find my mistake soon.

Think about the following code I want to parse bases on a real case:

let targetText = "James Bond (@james007@mastodon.social)";

I want to capture "James Bond" as the name and "@james007@mastodon.social" as the Blog Title. My understanding is that the following snippet of code should work in basic Javascript (you can copy and paste the code in the Firefox development view and test it in the console):

let targetText = "James Bond (@james007@mastodon.social)";
let my_regexp = /^(?.+) \((?[^]+)\)$/;
let myGroups = targetText.match(my_regexp).groups;
alert(myGroups.name);
alert(myGroups.blog);

However, when trying it in my Scaffold code, I get a "SyntaxError: invalid regexp group". What am I missing?

PS: The code is based on the guidelins of: https://javascript.info/regexp-groups
  • named groups is a very new javascript feature. Compatibility was introduced in Firefox 78, Zotero is based on FF 68 EST. (It also seems like overkill here; just use [1] and [2])

This is an old discussion that has not been active in a long time. Before commenting here, you should strongly consider starting a new discussion instead. If you think the content of this discussion is still relevant, you can link to it from your new discussion.

Sign In or Register to comment.