In javascript, one of the popular regex is to strip out HTML tags from the text. The code for that is
String.prototype.stripHTML = function () {
var reTag = /<(?:.|\s)*?>/g;
return this.replace(reTag, "");
};
If you try this on "<b>This would be bold</b>".stripHTML(), then it outputs as "This would be bold". Shouldn’t it output as "" ?
Doesn’t this regex says that match everything which starts with < and ends with > ? Why didn’t this regex start at < of <b> and end at > of </b>
You are using a non-greedy modifier.
This causes the match to be the shortest possible, instead of the default which is to match the longest possible match.