David's Random Projects and Documents
Feel free to use and link to any docs you find here. Please give credit and link back to this page on any publicly avaliable copies.

MultiRegExp: Regular expression formatter

MultiRegExp is a javascript regular expression extension which allows the capture of index values in addition to the strings normally returned from capture groups. It does this by inserting capture groups between all groups in the original regular expression and computing the index of the original groups using the lengths of all preceding matched groups. The git repo can be found here.

Usage:

var exp = new MultiRegExp(/([a-z]+)(?:\s|_)*([0-9]+)/i);
exp.exec("test_53"); //will return {0: {index:0, text:'test'}, 1: {index:5, text:'53'}}

Try Me

Regex:
Test String:

Output:



This extension was inspired in by bobince's answer to How to find index of groups in match .