Creating a Regular expression which matches python tuple structure

I'm doing a JavaScript plugin, launched at every page-load, that replaces every matching structure with a link... That link redirects to a web application/database. A resource for coders of the Mount&Blade game.

In theory is easy, but I've found an huge obstacle in my way to the success: Regular expressions.

Even helped by a program named QuickRegex I can't get the structure to match. Or if I don't do a proper conditioning it outputs wrong results. The matching structure is as follows:

(item_set_slot, "itm_heavy_crossbow", slot_item_multiplayer_item_class),

I want to pick item_set_slot and turn it into a link to$1

This is the code I'm using, that works, more or less. ;)

/* Mount&Blade Command Database Linking by Swyter */
function swymbcommandshooker(){
/* Regular HTML Expressions */
document.getElementsByTagName("body")[0].innerHTML=document.getElementsByTagName("body")[0].innerHTML.replace(/[\(]([a-zA-Z_]+)[\,]/gi, "(<a href='$1' title='[?] Take an look in the Command Database' target='_blank'>$1</a>,");

/* Python highlighter Support...*/
document.getElementsByTagName("body")[0].innerHTML=document.getElementsByTagName("body")[0].innerHTML.replace(/&#40;</span>([_a-z]+)\,/gi, "&#40;</span><a href='$1' title='[?] Take an look in the Command Database' target='_blank'>$1</a>,");

addOnloadHook( swymbcommandshooker );

Thanks in advance.


Hm, I'm not sure if I have understand you correctly, but if you really just want the match "item_set_slot" in "(item_set_slot, "itm_heavy_crossbow", slot_item_multiplayer_item_class)," the following regex should do:


The JavaScript to generate the URL could look like this:

var tuple = '(item_set_slot, "itm_heavy_crossbow", slot_item_multiplayer_item_class),';
var url = tuple.replace(/^\(([a-z_]+),.*/i, '$1');

Note the appended .* in the regex, which is needed to match the rest of the tuple.

Need Your Help

Push a merge conflicted branch

git github

In our project we have quarterly release out which 2 months are for development and 1 months is for UAT. Our is a very big project and there are around 20 teams in our project each working on some

What is PhoneGap used for, exactly?

cordova hybrid

I have a couple of years of experience developing native Android apps, and was curious about making a HTML5/CSS3/JS version of these so I can publish them for iOS as well.