Comment 139 for bug 134813

Revision history for this message
In , Neil-httl (neil-httl) wrote :

(In reply to comment #69)
> function offsetToWord(data, offset) {
> var m1 = data.substr(0, offset).match(/\w+$/) || "";
> var m2 = data.substr(offset).match(/^\w+/) || "";
Unfortunately all of the regexp methods return an array of matches (including any parenthetical captures) rather than the matching string itself. You could however use \w* instead of \w+ to force a match to exist, e.g.
var m1 = data.substr(0, offset).match(/\w*$/)[0];