Skip to content

Commit

Permalink
Ok. I really fixed that regex extension bug this time.
Browse files Browse the repository at this point in the history
You can't grab groups in string.replace() that way :/
  • Loading branch information
derobins committed Feb 25, 2009
1 parent e5365c0 commit 46cb189
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions wmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ Attacklab.wmdBase = function(){

// Replace the flags with empty space and store them.
// Technically, this can match incorrect flags like "gmm".
pattern = pattern.replace(/\/([gim]*)$/, "");
if (re.lastMatch !== "/") {
flags = re.$1;
var result = pattern.match(/\/([gim]*)$/);
if (result === null) {
flags = result[0];
}
else {
flags = "";
}

// Remove the slash delimiters on the regular expression.
pattern = pattern.replace(/(^\/|\/$)/g, "");
// Remove the flags and slash delimiters from the regular expression.
pattern = pattern.replace(/(^\/|\/[gim]*$)/g, "");
pattern = pre + pattern + post;

return new RegExp(pattern, flags);
Expand Down

0 comments on commit 46cb189

Please sign in to comment.