Following code snippet shows how can we use back reference to remove duplicate word from string.
var test = "personal personal computers and super computers computers";
test = test.replace(/(\w+)\s+\1/g,"$1");
alert(test);
Thanks to Cracki for pointing out difference between back reference and back tracking.
1 comment:
that's not backtracking. that's back-*references*.
Post a Comment