Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

find every character string match JavaScript

function indexesOf(string, regex) {
    var match,
        indexes = {};

    regex = new RegExp(regex);

    while (match = regex.exec(string)) {
        if (!indexes[match[0]]) indexes[match[0]] = [];
        indexes[match[0]].push(match.index);
    }

    return indexes;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #character #string #match #JavaScript
ADD COMMENT
Topic
Name
2+1 =